Skip to content

Commit

Permalink
Make swc jest configurable without a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoBrusa committed Jul 4, 2023
1 parent bd3e79c commit 757217d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/polite-chefs-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'modular-scripts': minor
---

Use of swc Jest for testing can now be configured through modular configuration
file
15 changes: 13 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
externalAllowList: ['**'],
publicUrl: '',
generateSourceMap: true,
swcJest: false,
};
```

Expand Down Expand Up @@ -69,8 +70,8 @@ esm.sh. Only applies to ESM Views.
Packages that should be bundled and not fetched from a CDN. We recommend
allowing all packages to be handled by the CDN, except for particular cases
where they would not work correctly. See
[known-limitations](./esm-views/known-limitations.md). Defaults to none. Only
applies to ESM Views.
[customize bundle strategy](./esm-views/customize-bundle-strategy.md). Defaults
to none. Only applies to ESM Views.

### externalAllowList

Expand Down Expand Up @@ -103,6 +104,16 @@ Should build process generate a source map - can be disabled for performance
reasons. Source maps are resource heavy and can cause out of memory issue for
large source files.

### swcJest

**Type**: `boolean`

**Default**: `false`

Use Rust based SWC Jest runner instead of ts-jest & babel for performance
improvements. Can be breaking for certain tests and configurations. Cannot be
configured per package, must be configured at root.

## `package.json#modular`

_NOTE: This property is created automatically and is described here for
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint:fix": "yarn lint --fix",
"create-modular-react-app": "ts-node packages/create-modular-react-app/src/cli.ts",
"modular": "ts-node packages/modular-scripts/src/cli.ts",
"test": "cross-env NODE_OPTIONS=--max_old_space_size=5120 yarn modular test --swc --runInBand --env=node",
"test": "cross-env NODE_OPTIONS=--max_old_space_size=5120 yarn modular test --runInBand --env=node",
"build": "yarn workspace @modular-scripts/workspace-resolver build && yarn workspace create-modular-react-app build && yarn workspace modular-scripts build && yarn modular build @modular-scripts/remote-view && yarn prepare:remote-view",
"prepare": "is-ci || husky install",
"prepare:remote-view:copy": "cp -R dist/modular-scripts-remote-view packages/remote-view/dist",
Expand Down Expand Up @@ -106,7 +106,8 @@
"coverageProvider": "v8"
},
"modular": {
"type": "root"
"type": "root",
"swcJest": true
},
"lint-staged": {
"*.{js,ts,tsx,mjs,md,yml,json}": "yarn prettier --write -l",
Expand Down
11 changes: 10 additions & 1 deletion packages/modular-scripts/src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
computeRegexesFromPackageNames,
partitionPackages,
} from '../utils/unobtrusiveModular';
import { getConfig } from '../utils/config';

export interface TestOptions {
bypass: boolean;
Expand Down Expand Up @@ -91,10 +92,18 @@ async function test(options: TestOptions, packages?: string[]): Promise<void> {
// pass in jest configuration
const { createJestConfig } = await import('./config');

const configuredSwc = swc ? swc : getConfig('swcJest', getModularRoot());
console.error(
'CONFIGURED SWC: ',
JSON.stringify(getConfig('swcJest', getModularRoot())),
);

if (configuredSwc) console.error('USING SWC');

cleanArgv.push(
'--config',
generateJestConfig(
createJestConfig({ reporters, testResultsProcessor }, swc),
createJestConfig({ reporters, testResultsProcessor }, configuredSwc),
),
);

Expand Down
8 changes: 8 additions & 0 deletions packages/modular-scripts/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Config {
externalAllowList: string[];
publicUrl: string;
generateSourceMap: boolean;
swcJest: boolean;
}

type ConfigDefs = {
Expand Down Expand Up @@ -77,6 +78,13 @@ const defs: ConfigDefs = {
? process.env.GENERATE_SOURCEMAP === 'true'
: undefined,
},
swcJest: {
default: false,
override:
process.env.SWC_JEST === 'true' || process.env.SWC_JEST === 'false'
? process.env.SWC_JEST === 'true'
: undefined,
},
};

const explorer = cosmiconfigSync('modular', { searchPlaces });
Expand Down

0 comments on commit 757217d

Please sign in to comment.