Skip to content

Commit efe716f

Browse files
chore: improve transform configs on sdk (#2643)
Co-authored-by: ScriptedAlchemy <[email protected]> Co-authored-by: Matteo Pietro Dazzi <[email protected]>
1 parent f75b277 commit efe716f

File tree

11 files changed

+170
-90
lines changed

11 files changed

+170
-90
lines changed

packages/bridge/bridge-react/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
__DEV__: true,
77
__TEST__: true,
88
__BROWSER__: false,
9-
__VERSION__: '"unknow"',
9+
__VERSION__: '"unknown"',
1010
__APP_VERSION__: '"0.0.0"',
1111
},
1212
plugins: [nxViteTsPaths()],

packages/chrome-devtools/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default defineConfig({
55
__DEV__: true,
66
__TEST__: true,
77
__BROWSER__: false,
8-
__VERSION__: '"unknow"',
8+
__VERSION__: '"unknown"',
99
},
1010
test: {
1111
environment: 'jsdom',

packages/managers/.swcrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"jsc": {
3+
"target": "es2017",
4+
"parser": {
5+
"syntax": "typescript",
6+
"decorators": true,
7+
"dynamicImport": true
8+
},
9+
"transform": {
10+
"decoratorMetadata": true,
11+
"legacyDecorator": true
12+
},
13+
"keepClassNames": true,
14+
"externalHelpers": true,
15+
"loose": true
16+
},
17+
"module": {
18+
"type": "es6"
19+
},
20+
"sourceMaps": true,
21+
"exclude": [
22+
"jest.config.ts",
23+
"./src/jest-setup.ts$",
24+
"./**/jest-setup.ts$",
25+
".*.js$"
26+
]
27+
}

packages/managers/jest.config.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
// For a detailed explanation regarding each configuration property, visit:
2-
// https://jestjs.io/docs/en/configuration.html
1+
/* eslint-disable */
2+
const { readFileSync } = require('fs');
3+
4+
// Reading the SWC compilation config and remove the "exclude"
5+
// for the test files to be compiled by SWC
6+
const { exclude: _, ...swcJestConfig } = JSON.parse(
7+
readFileSync(`${__dirname}/.swcrc`, 'utf-8'),
8+
);
9+
10+
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
11+
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
12+
swcJestConfig.swcrc ??= false;
13+
// Uncomment if using global setup/teardown files being transformed via swc
14+
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
15+
// jest needs EsModule Interop to find the default exported setup/teardown functions
16+
// swcJestConfig.module.noInterop = false;
317

418
module.exports = {
519
clearMocks: true,
20+
cache: false,
621
testEnvironment: 'jsdom',
722
coveragePathIgnorePatterns: ['__tests__', '/node_modules/'],
8-
coverageProvider: 'v8',
9-
coverageReporters: ['cobertura', 'clover', 'json', 'lcov', 'text'],
1023
globals: {
1124
__DEV__: true,
1225
__TEST__: true,
1326
__BROWSER__: false,
14-
__VERSION__: '"unknow"',
27+
__VERSION__: '"unknown"',
1528
},
1629
preset: 'ts-jest',
1730
transformIgnorePatterns: [
1831
// Change MODULE_NAME_HERE to your module that isn't being compiled
1932
'/node_modules/(?!((@byted/garfish-)|(byted-tea-sdk))).+\\.js$',
2033
],
2134
transform: {
22-
'^.+\\.(t|j)sx?$': ['@swc/jest'],
35+
'^.+\\.(t|j)sx?$': ['@swc/jest', swcJestConfig],
2336
},
2437
rootDir: __dirname,
2538
testMatch: ['<rootDir>__tests__/**/**.spec.[jt]s?(x)'],

packages/manifest/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
__DEV__: true,
1212
__TEST__: true,
1313
__BROWSER__: false,
14-
__VERSION__: '"unknow"',
14+
__VERSION__: '"unknown"',
1515
},
1616
preset: 'ts-jest',
1717
transformIgnorePatterns: [

packages/rspack/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
__DEV__: true,
1212
__TEST__: true,
1313
__BROWSER__: false,
14-
__VERSION__: '"unknow"',
14+
__VERSION__: '"unknown"',
1515
},
1616
preset: 'ts-jest',
1717
transformIgnorePatterns: [

packages/runtime/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
__DEV__: true,
77
__TEST__: true,
88
__BROWSER__: false,
9-
__VERSION__: '"unknow"',
9+
__VERSION__: '"unknown"',
1010
},
1111
plugins: [nxViteTsPaths()],
1212
test: {

packages/sdk/.swcrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"jsc": {
3+
"target": "es2017",
4+
"parser": {
5+
"syntax": "typescript",
6+
"decorators": true,
7+
"dynamicImport": true
8+
},
9+
"transform": {
10+
"decoratorMetadata": true,
11+
"legacyDecorator": true
12+
},
13+
"keepClassNames": true,
14+
"externalHelpers": true,
15+
"loose": true
16+
},
17+
"module": {
18+
"type": "es6"
19+
},
20+
"sourceMaps": true,
21+
"exclude": [
22+
"jest.config.ts",
23+
"./src/jest-setup.ts$",
24+
"./**/jest-setup.ts$",
25+
".*.js$"
26+
]
27+
}

packages/sdk/jest.config.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
// For a detailed explanation regarding each configuration property, visit:
2-
// https://jestjs.io/docs/en/configuration.html
1+
/* eslint-disable */
2+
const { readFileSync } = require('fs');
3+
4+
// Reading the SWC compilation config and remove the "exclude"
5+
// for the test files to be compiled by SWC
6+
const { exclude: _, ...swcJestConfig } = JSON.parse(
7+
readFileSync(`${__dirname}/.swcrc`, 'utf-8'),
8+
);
9+
10+
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
11+
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
12+
swcJestConfig.swcrc ??= false;
13+
// Uncomment if using global setup/teardown files being transformed via swc
14+
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
15+
// jest needs EsModule Interop to find the default exported setup/teardown functions
16+
// swcJestConfig.module.noInterop = false;
317

418
module.exports = {
519
clearMocks: true,
20+
cache: false,
621
testEnvironment: 'jsdom',
722
coveragePathIgnorePatterns: ['__tests__', '/node_modules/'],
8-
coverageProvider: 'v8',
9-
coverageReporters: ['cobertura', 'clover', 'json', 'lcov', 'text'],
1023
globals: {
1124
__DEV__: true,
1225
__TEST__: true,
1326
__BROWSER__: false,
14-
__VERSION__: '"unknow"',
27+
__VERSION__: '"unknown"',
1528
},
1629
preset: 'ts-jest',
1730
transformIgnorePatterns: [
1831
// Change MODULE_NAME_HERE to your module that isn't being compiled
1932
'/node_modules/(?!((@byted/garfish-)|(byted-tea-sdk))).+\\.js$',
2033
],
2134
transform: {
22-
'^.+\\.(t|j)sx?$': ['@swc/jest'],
35+
'^.+\\.(t|j)sx?$': ['@swc/jest', swcJestConfig],
2336
},
2437
rootDir: __dirname,
2538
testMatch: ['<rootDir>__tests__/**/**.spec.[jt]s?(x)'],

packages/webpack-bundler-runtime/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
__DEV__: true,
1212
__TEST__: true,
1313
__BROWSER__: false,
14-
__VERSION__: '"unknow"',
14+
__VERSION__: '"unknown"',
1515
},
1616
preset: 'ts-jest',
1717
transformIgnorePatterns: [

0 commit comments

Comments
 (0)