Skip to content
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

Support transforming testRunner with preset/transform #8823

Merged
merged 5 commits into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `[jest-snapshot]`: [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792))
- `[jest-repl, jest-runner]` [**BREAKING**] Run transforms over environment ([#8751](https://github.com/facebook/jest/pull/8751))
- `[jest-runner]` [**BREAKING**] Run transforms over `runnner` ([#8823](https://github.com/facebook/jest/pull/8823))
- `[jest-runner]` [**BREAKING**] Run transforms over `testRunnner` ([#8823](https://github.com/facebook/jest/pull/8823))

### Fixes

Expand Down
11 changes: 11 additions & 0 deletions e2e/__tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,14 @@ describe('transform-runner', () => {
expect(json.numPassedTests).toBe(1);
});
});

describe('transform-testrunner', () => {
const dir = path.resolve(__dirname, '../transform/transform-testrunner');

it('should transform testRunner', () => {
const {json, stderr} = runWithJson(dir, ['--no-cache']);
expect(stderr).toMatch(/PASS/);
expect(json.success).toBe(true);
expect(json.numPassedTests).toBe(1);
});
});
6 changes: 5 additions & 1 deletion e2e/async-regenerator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"@babel/polyfill": "^7.2.5"
},
"jest": {
"testEnvironment": "node"
"testEnvironment": "node",
"transformIgnorePatterns": [
"jest-circus",
"jest-jasmine2"
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SimenB This was the reason the last test was failing. Adding it manually to transformIgnorePatterns, again as mentioned in a comment below these ignores are needed only when testing the jest repo, any consumers will not need to add these as these will be within node_modules

}
}
4 changes: 3 additions & 1 deletion e2e/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"automock": true,
"testEnvironment": "node",
"transformIgnorePatterns": [
"/jest-environment-node/"
"jest-circus",
"jest-environment-node",
"jest-jasmine2"
]
}
}
5 changes: 4 additions & 1 deletion e2e/coverage-transform-instrumented/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"testRegex": "/__tests__/.*\\.(js)$",
"testEnvironment": "node",
"transformIgnorePatterns": [
"/jest-environment-node/"
"jest-circus",
"jest-each",
"jest-environment-node/",
"jest-jasmine2"
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These will have to be ignored manually as a relative path to the package is used rather than node_modules.
Seems like the number of ignore paths might increase going forward, one idea I had was to add a pattern like jest-, but that doesn't seem to work in all cases

"moduleFileExtensions": [
"js"
Expand Down
5 changes: 4 additions & 1 deletion e2e/transform-linked-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"/node_modules/",
"<rootDir>/__tests__",
"<rootDir>/ignored/",
"/jest-environment-node/"
"jest-circus",
"jest-each",
"jest-environment-node",
"jest-jasmine2"
],
"transform": {
"\\.js$": "<rootDir>/preprocessor.js"
Expand Down
11 changes: 10 additions & 1 deletion e2e/transform/babel-jest-ignored/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

module.exports = {only: ['blablabla', /jest-environment-node/]};
module.exports = {
only: [
'blablabla',
/jest-circus/,
/jest-each/,
/jest-environment-node/,
/jest-jasmine2/,
/jest-source-map/,
],
};
4 changes: 3 additions & 1 deletion e2e/transform/multiple-transformers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
},
"testEnvironment": "node",
"transformIgnorePatterns": [
"/jest-environment-node/"
"jest-circus",
"jest-environment-node",
"jest-jasmine2"
]
},
"dependencies": {
Expand Down
10 changes: 10 additions & 0 deletions e2e/transform/transform-testrunner/__tests__/add.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

it('should add two numbers', () => {
expect(1 + 1).toBe(2);
});
13 changes: 13 additions & 0 deletions e2e/transform/transform-testrunner/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
10 changes: 10 additions & 0 deletions e2e/transform/transform-testrunner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jest": {
"rootDir": "./",
"testRunner": "<rootDir>/test-runner.ts"
},
"dependencies": {
"@babel/preset-env": "^7.0.0",
"@babel/preset-typescript": "^7.0.0"
}
}
36 changes: 36 additions & 0 deletions e2e/transform/transform-testrunner/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {JestEnvironment} from '@jest/environment';
import {TestResult, createEmptyTestResult} from '@jest/test-result';
import {Config} from '@jest/types';
import Runtime from 'jest-runtime';

export default async function testRunner(
globalConfig: Config.GlobalConfig,
config: Config.ProjectConfig,
environment: JestEnvironment,
runtime: Runtime,
testPath: string,
): Promise<TestResult> {
return {
...createEmptyTestResult(),
numPassingTests: 1,
testFilePath: testPath,
testResults: [
{
ancestorTitles: [],
duration: 2,
failureMessages: [],
fullName: 'sample test',
location: null,
numPassingAsserts: 1,
status: 'passed',
title: 'sample test',
},
],
};
}
6 changes: 6 additions & 0 deletions e2e/transform/transform-testrunner/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
}
}
1 change: 1 addition & 0 deletions packages/jest-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@jest/console": "^26.6.2",
"@jest/environment": "^26.6.2",
"@jest/test-result": "^26.6.2",
"@jest/transform": "^26.6.2",
Copy link
Member

Choose a reason for hiding this comment

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

Add to references in tsconfig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's present in tsconfig.json.
Sorry this line should have been part of #8751 , got missed in the rebase I'll be more careful next time

https://github.com/facebook/jest/blob/68d68f5282bb11f93cc24ac41634667469138878/packages/jest-runner/tsconfig.json#L18

"@jest/types": "^26.6.2",
"@types/node": "*",
"chalk": "^4.0.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/jest-runner/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ async function runTestInternal(
transformer.requireAndTranspileModule(testEnvironment),
).default;
const testFramework: TestFramework = interopRequireDefault(
process.env.JEST_CIRCUS === '1'
? // eslint-disable-next-line import/no-extraneous-dependencies
require('jest-circus/runner')
: require(config.testRunner),
transformer.requireAndTranspileModule(
process.env.JEST_CIRCUS === '1'
? 'jest-circus/runner'
: config.testRunner,
),
).default;
const Runtime: typeof RuntimeClass = interopRequireDefault(
config.moduleLoader
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12126,6 +12126,7 @@ fsevents@~2.1.2:
"@jest/console": ^26.6.2
"@jest/environment": ^26.6.2
"@jest/test-result": ^26.6.2
"@jest/transform": ^26.6.2
"@jest/types": ^26.6.2
"@types/exit": ^0.1.30
"@types/graceful-fs": ^4.1.2
Expand Down