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

Change the way setting up the framework works #4976

Merged
merged 1 commit into from
Nov 29, 2017
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
"transform": {
"^.+\\.js$": "<rootDir>/packages/babel-jest"
},
"setupTestFrameworkScriptFile": "<rootDir>/test_setup_file.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoops, this should stay where it was. #4994

"setupTestFramework": [
"<rootDir>/test_setup_file.js"
],
"snapshotSerializers": [
"<rootDir>/packages/pretty-format/build/plugins/convert_ansi.js"
],
Expand Down
8 changes: 7 additions & 1 deletion packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,13 @@ export const options = {
setupFiles: {
description:
'The paths to modules that run some code to configure or ' +
'set up the testing environment before each test. ',
'set up the testing environment before each test.',
type: 'array',
},
setupTestFramework: {
description:
'Allows to setup the Jasmine environment from the global namespace, ' +
'instead of injecting the module inside the context',
type: 'array',
},
setupTestFrameworkScriptFile: {
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const getConfigs = (
roots: options.roots,
runner: options.runner,
setupFiles: options.setupFiles,
setupTestFramework: options.setupTestFramework,
setupTestFrameworkScriptFile: options.setupTestFrameworkScriptFile,
skipNodeResolution: options.skipNodeResolution,
snapshotSerializers: options.snapshotSerializers,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
value = normalizeCollectCoverageOnlyFrom(options, key);
break;
case 'setupFiles':
case 'setupTestFramework':
case 'snapshotSerializers':
value =
options[key] &&
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/valid_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default ({
runTestsByPath: false,
runner: 'jest-runner',
setupFiles: ['<rootDir>/setup.js'],
setupTestFrameworkScriptFile: '<rootDir>/test_setup_file.js',
setupTestFramework: ['<rootDir>/test_setup_file.js'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

@SimenB I meant this line, sorry!

silent: true,
skipNodeResolution: false,
snapshotSerializers: ['my-serializer-module'],
Expand Down
6 changes: 6 additions & 0 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ async function jasmine2(
runtime.requireModule(config.setupTestFrameworkScriptFile);
}

if (config.setupTestFramework && config.setupTestFramework.length) {
config.setupTestFramework.forEach(module => {
require(module)(environment.global);
});
}

runtime
.requireModule(require.resolve('source-map-support'), 'source-map-support')
.install({
Expand Down
20 changes: 13 additions & 7 deletions test_setup_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@

const jasmineReporters = require('jasmine-reporters');

// Some of the `jest-runtime` tests are very slow and cause
// timeouts on travis
jest.setTimeout(70000);
module.exports = function(global) {
const {jasmine} = global;

if (global.jasmine && process.env.APPVEYOR_API_URL) {
// Running on AppVeyor, add the custom reporter.
jasmine.getEnv().addReporter(new jasmineReporters.AppVeyorReporter());
}
if (jasmine) {
// Some of the `jest-runtime` tests are very slow and cause timeouts on
// Travis CI.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 70000;

// Running on AppVeyor, add the custom reporter.
if (process.env.APPVEYOR_API_URL) {
jasmine.getEnv().addReporter(new jasmineReporters.AppVeyorReporter());
}
}
};
1 change: 1 addition & 0 deletions test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
roots: [],
runner: 'jest-runner',
setupFiles: [],
setupTestFramework: [],
setupTestFrameworkScriptFile: null,
skipNodeResolution: false,
snapshotSerializers: [],
Expand Down
1 change: 1 addition & 0 deletions types/Argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type Argv = {|
rootDir: string,
roots: Array<string>,
setupFiles: Array<string>,
setupTestFramework: Array<string>,
setupTestFrameworkScriptFile: string,
silent: boolean,
snapshotSerializers: Array<string>,
Expand Down
2 changes: 2 additions & 0 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export type InitialOptions = {
runTestsByPath?: boolean,
scriptPreprocessor?: string,
setupFiles?: Array<Path>,
setupTestFramework?: Array<Path>,
setupTestFrameworkScriptFile?: Path,
silent?: boolean,
skipNodeResolution?: boolean,
Expand Down Expand Up @@ -218,6 +219,7 @@ export type ProjectConfig = {|
roots: Array<Path>,
runner: string,
setupFiles: Array<Path>,
setupTestFramework: Array<Path>,
setupTestFrameworkScriptFile: ?Path,
skipNodeResolution: boolean,
snapshotSerializers: Array<Path>,
Expand Down