Skip to content

chore: use swc for tests instead of Babel #4584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 2, 2022
21 changes: 21 additions & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
coverageReporters: ['text-summary', 'lcov'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
resolver: '<rootDir>/../../tests/jest-resolver.js',
transform: {
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
target: 'es2019',
},
},
],
},
};
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,14 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"devDependencies": {
"@babel/code-frame": "^7.16.0",
"@babel/parser": "^7.16.4",
"@babel/types": "^7.16.0",
"@commitlint/cli": "^16.0.1",
"@commitlint/config-conventional": "^16.0.0",
"@nrwl/cli": "13.0.2",
"@nrwl/nx-cloud": "12.5.1",
"@nrwl/tao": "13.0.2",
"@nrwl/workspace": "13.0.2",
"@types/babel__code-frame": "^7.0.3",
"@swc/core": "^1.2.143",
"@swc/jest": "^0.2.17",
"@types/debug": "^4.1.7",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/glob": "^7.2.0",
Expand All @@ -81,6 +79,7 @@
"@types/tmp": "^0.2.2",
"all-contributors-cli": "^6.20.0",
"cross-env": "^7.0.3",
"cross-fetch": "^3.1.4",
"cspell": "^5.12.3",
"cz-conventional-changelog": "^3.3.0",
"downlevel-dts": "^0.9.0",
Expand All @@ -100,12 +99,10 @@
"make-dir": "^3.1.0",
"markdownlint-cli": "^0.29.0",
"ncp": "^2.0.0",
"cross-fetch": "^3.1.4",
"prettier": "^2.5.0",
"pretty-format": "^27.3.1",
"rimraf": "^3.0.2",
"tmp": "^0.2.1",
"ts-jest": "^27.0.5",
"ts-node": "^10.4.0",
"tslint": "^6.1.3",
"typescript": ">=3.3.1 <4.6.0"
Expand Down
14 changes: 1 addition & 13 deletions packages/ast-spec/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
globals: {
'ts-jest': {
isolatedModules: true,
},
},
testEnvironment: 'node',
transform: {
['^.+\\.tsx?$']: 'ts-jest',
},
...require('../../jest.config.base.js'),
testRegex: ['./tests/.+\\.test\\.ts$'],
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageReporters: ['text-summary', 'lcov'],
};
15 changes: 1 addition & 14 deletions packages/eslint-plugin-internal/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
resolver: '<rootDir>/../../tests/jest-resolver.js',
globals: {
'ts-jest': {
isolatedModules: true,
},
},
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
...require('../../jest.config.base.js'),
testRegex: './tests/.+\\.test\\.ts$',
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageReporters: ['text-summary', 'lcov'],
};
15 changes: 1 addition & 14 deletions packages/eslint-plugin-tslint/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
resolver: '<rootDir>/../../tests/jest-resolver.js',
globals: {
'ts-jest': {
isolatedModules: true,
},
},
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
...require('../../jest.config.base.js'),
testRegex: './tests/.+\\.spec\\.ts$',
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageReporters: ['text-summary', 'lcov'],
};
14 changes: 1 addition & 13 deletions packages/eslint-plugin/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
resolver: '<rootDir>/../../tests/jest-resolver.js',
globals: {
'ts-jest': {
isolatedModules: true,
},
},
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
...require('../../jest.config.base.js'),
testRegex: './tests/.+\\.test\\.ts$',
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageReporters: ['text-summary', 'lcov'],
};
85 changes: 41 additions & 44 deletions packages/eslint-plugin/src/rules/consistent-type-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,57 +85,54 @@ export default util.createRule({
}),
...(option === 'type' && {
TSInterfaceDeclaration(node): void {
const fix = isCurrentlyTraversedNodeWithinModuleDeclaration()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes don't do anything other than get us around swc-project/swc#3672

? null
: (fixer: TSESLint.RuleFixer): TSESLint.RuleFix[] => {
const typeNode = node.typeParameters ?? node.id;
const fixes: TSESLint.RuleFix[] = [];

const firstToken = sourceCode.getTokenBefore(node.id);
if (firstToken) {
fixes.push(fixer.replaceText(firstToken, 'type'));
fixes.push(
fixer.replaceTextRange(
[typeNode.range[1], node.body.range[0]],
' = ',
),
);
}

if (node.extends) {
node.extends.forEach(heritage => {
const typeIdentifier = sourceCode.getText(heritage);
fixes.push(
fixer.insertTextAfter(node.body, ` & ${typeIdentifier}`),
);
});
}

if (
node.parent?.type === AST_NODE_TYPES.ExportDefaultDeclaration
) {
fixes.push(
fixer.removeRange([node.parent.range[0], node.range[0]]),
fixer.insertTextAfter(
node.body,
`\nexport default ${node.id.name}`,
),
);
}

return fixes;
};
context.report({
node: node.id,
messageId: 'typeOverInterface',
/**
* remove automatically fix when the interface is within a declare global
* @see {@link https://github.com/typescript-eslint/typescript-eslint/issues/2707}
*/
fix: isCurrentlyTraversedNodeWithinModuleDeclaration()
? null
: (fixer): TSESLint.RuleFix[] => {
const typeNode = node.typeParameters ?? node.id;
const fixes: TSESLint.RuleFix[] = [];

const firstToken = sourceCode.getTokenBefore(node.id);
if (firstToken) {
fixes.push(fixer.replaceText(firstToken, 'type'));
fixes.push(
fixer.replaceTextRange(
[typeNode.range[1], node.body.range[0]],
' = ',
),
);
}

if (node.extends) {
node.extends.forEach(heritage => {
const typeIdentifier = sourceCode.getText(heritage);
fixes.push(
fixer.insertTextAfter(
node.body,
` & ${typeIdentifier}`,
),
);
});
}

if (
node.parent?.type ===
AST_NODE_TYPES.ExportDefaultDeclaration
) {
fixes.push(
fixer.removeRange([node.parent.range[0], node.range[0]]),
fixer.insertTextAfter(
node.body,
`\nexport default ${node.id.name}`,
),
);
}

return fixes;
},
fix,
});
},
}),
Expand Down
Loading