Skip to content

Commit

Permalink
enforce type checking on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alshdavid committed Dec 16, 2024
1 parent c2c3540 commit ccc8de9
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const args = process.argv.slice(2);

function isFileArg(file) {
return (
/\.(j|t)s$/.test(file) ||
/\.(j|t|cj|mj|ct|mt)s$/.test(file) ||
(fs.existsSync(file) && fs.statSync(file).isDirectory())
);
}

const spec = args.some(isFileArg)
? args.filter(isFileArg)
: 'packages/*/!(integration-tests)/test/{*.{js,ts},**/*.{test,spec}.{js,ts}}';
: 'packages/*/!(integration-tests)/test/{*.{js,ts,cts,mts,cjs,mjs},**/*.{test,spec}.{js,ts,mts,cts,cjs,mjs}}';

module.exports = {
spec,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"test:js": "yarn test:js:unit && yarn test:integration",
"test:js:coverage": "yarn nyc yarn test:js:unit",
"test:js:coverage:report": "yarn nyc report --reporter=html-spa",
"test:js:unit": "cross-env NODE_ENV=test mocha --conditions=development --timeout 5000",
"test:js:unit": "cross-env NODE_ENV=test mocha --conditions=\"@atlaspack::sources\" --timeout 5000",
"test:unit": "yarn test:js:unit && cargo test",
"dev:release": "SKIP_PLUGIN_COMPATIBILITY_CHECK=true lerna publish -y --canary --preid dev --dist-tag=dev --exact --force-publish=* --no-git-tag-version --no-push",
"canary:release": "SKIP_PLUGIN_COMPATIBILITY_CHECK=true lerna publish -y --canary --preid canary --dist-tag=canary --exact --force-publish=* --no-git-tag-version --no-push",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"./*": "./*",
".": "./lib/index.js",
"./worker": {
"development": "./src/worker.js",
"@atlaspack::sources": "./src/worker.js",
"default": "./lib/worker.js"
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/core/integration-tests/test/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1473,14 +1473,14 @@ describe('bundler', function () {
{
"extends": "@atlaspack/config-default",
"transformers": {
"*.js": ["./transformer.js", "..."],
"*.js": ["./transformer.cjs", "..."],
}
}
transformer.js:
import { Transformer } from '@atlaspack/plugin';
transformer.cjs:
const { Transformer } = require('@atlaspack/plugin');
export default new Transformer({
module.exports = new Transformer({
transform({asset}) {
if (asset.filePath.endsWith('.html')) {
asset.isBundleSplittable = false;
Expand Down
6 changes: 6 additions & 0 deletions packages/core/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
},
"main": "lib/Logger.js",
"source": "src/Logger.js",
"exports": {
".": {
"@atlaspack::sources": "./src/Logger.js",
"default": "./lib/Logger.js"
}
},
"engines": {
"node": ">= 16.0.0"
},
Expand Down
14 changes: 14 additions & 0 deletions packages/core/workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
"engines": {
"node": ">= 16.0.0"
},
"exports": {
".": {
"types": "./index.d.ts",
"@atlaspack::sources": "./src/index.js",
"default": "./lib/index.js"
}
},
"imports": {
"#atlaspack/workers": {
"types": "./index.d.ts",
"@atlaspack::sources": "./src/index.js",
"default": "./lib/index.js"
}
},
"dependencies": {
"@atlaspack/build-cache": "2.12.0",
"@atlaspack/diagnostic": "2.12.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WorkerFarm = require('../../../src/WorkerFarm').default;
const WorkerFarm = require('#atlaspack/workers').default;

function run() {
if (WorkerFarm.isWorker()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WorkerFarm = require('../../../src/WorkerFarm').default;
const WorkerFarm = require('#atlaspack/workers').default;

function run(api) {
let result = [process.pid];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/workers/test/integration/workerfarm/ipc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WorkerFarm = require('../../../src/WorkerFarm').default;
const WorkerFarm = require('#atlaspack/workers').default;

function run(api, a, b) {
return api.callMaster({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WorkerFarm = require('../../../src/WorkerFarm').default;
const WorkerFarm = require('#atlaspack/workers').default;
const Logger = require('@atlaspack/logger').default;

function run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @flow
import Logger from '@atlaspack/logger';
import assert from 'assert';
import WorkerFarm from '../src';
// NOTE: @atlaspack/logger exports object instances from the module.
// If there are issues, check all imports are using the same module instance/path
const Logger = require('@atlaspack/logger').default;
const assert = require('assert');
const WorkerFarm = require('#atlaspack/workers').default;

describe('WorkerFarm', function () {
this.timeout(30000);
Expand Down
13 changes: 12 additions & 1 deletion packages/dev/babel-register/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const parcelBabelPreset = require('@atlaspack/babel-preset');
const path = require('path');
const fs = require('fs');

require('@babel/register')({
cwd: path.join(__dirname, '../../..'),
Expand All @@ -11,11 +12,21 @@ require('@babel/register')({
(filepath) =>
filepath.endsWith('.js') &&
filepath.includes('/core/integration-tests/test/integration'),
// Include tests
(filepath) =>
filepath.endsWith('.js') &&
!fs.readFileSync(filepath, 'utf8').trim().startsWith('// @flow'),
],
only: [path.join(__dirname, '../../..')],
presets: [parcelBabelPreset],
plugins: [require('./babel-plugin-module-translate')],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
extensions: ['.js', '.jsx'],
});

// This only support transpiling TypeScript to CJS
// eslint-disable-next-line import/no-extraneous-dependencies
require('esbuild-register/dist/node').register({
extensions: ['.ts', '.cts', '.mts'],
});

// This adds the registration to the Node args, which are passed
Expand Down
3 changes: 2 additions & 1 deletion packages/dev/babel-register/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dependencies": {
"@babel/register": "^7.22.5",
"@atlaspack/babel-preset": "2.12.0",
"resolve": "^1.12.0"
"resolve": "^1.12.0",
"esbuild-register": "^3.5.0"
},
"peerDependencies": {
"@babel/core": "^7.22.11"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {getBaseURL, stackTraceUrlRegexp} = require('./bundle-url-common');
const {getBaseURL, stackTraceUrlRegexp} = require('./bundle-url-common.cts');

const bundleURL: Record<string, string> = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {getBaseURL, stackTraceUrlRegexp} = require('./bundle-url-common');
const {getBaseURL, stackTraceUrlRegexp} = require('./bundle-url-common.cts');

const bundleURL = {};

Expand Down
2 changes: 1 addition & 1 deletion packages/runtimes/js/test/bundle-url-shards.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assert from 'assert';
import {fsFixture, overlayFS, bundle} from '@atlaspack/test-utils';

// $FlowFixMe importing TypeScript
import {getShardedBundleURL} from '../src/helpers/bundle-url-shards';
import {getShardedBundleURL} from '../src/helpers/bundle-url-shards.cts';

const createErrorStack = (url) => {
// This error stack is copied from a local dev, with a bunch
Expand Down

0 comments on commit ccc8de9

Please sign in to comment.