File tree Expand file tree Collapse file tree 7 files changed +29
-10
lines changed
jest-environment-jsdom/src Expand file tree Collapse file tree 7 files changed +29
-10
lines changed Original file line number Diff line number Diff line change 39
39
- ` [jest-worker] ` Add node worker-thread support to jest-worker ([ #7408 ] ( https://github.com/facebook/jest/pull/7408 ) )
40
40
- ` [jest-config] ` Allow ` bail ` setting to be configured with a number allowing tests to abort after ` n ` of failures ([ #7335 ] ( https://github.com/facebook/jest/pull/7335 ) )
41
41
- ` [jest-config] ` Allow % based configuration of ` --max-workers ` ([ #7494 ] ( https://github.com/facebook/jest/pull/7494 ) )
42
+ - ` [jest-runner] ` Instantiate the test environment class with the current ` testPath ` ([ #7442 ] ( https://github.com/facebook/jest/pull/7442 ) )
42
43
43
44
### Fixes
44
45
Original file line number Diff line number Diff line change @@ -789,13 +789,14 @@ Example:
789
789
const NodeEnvironment = require (' jest-environment-node' );
790
790
791
791
class CustomEnvironment extends NodeEnvironment {
792
- constructor (config ) {
793
- super (config);
792
+ constructor (config , context ) {
793
+ super (config, context);
794
+ this .testPath = context .testPath ;
794
795
}
795
796
796
797
async setup () {
797
798
await super .setup ();
798
- await someSetupTasks ();
799
+ await someSetupTasks (this . testPath );
799
800
this .global .someGlobalObject = createGlobalObject ();
800
801
}
801
802
Original file line number Diff line number Diff line change 9
9
'use strict' ;
10
10
11
11
import fs from 'fs' ;
12
+ import path from 'path' ;
12
13
import os from 'os' ;
13
14
import runJest from '../runJest' ;
14
15
import { cleanup } from '../Utils' ;
@@ -19,8 +20,18 @@ beforeEach(() => cleanup(DIR));
19
20
afterAll ( ( ) => cleanup ( DIR ) ) ;
20
21
21
22
it ( 'triggers setup/teardown hooks' , ( ) => {
23
+ const testDir = path . resolve (
24
+ __dirname ,
25
+ '..' ,
26
+ 'test-environment-async' ,
27
+ '__tests__' ,
28
+ ) ;
29
+ const testFile = path . join ( testDir , 'custom.test.js' ) ;
30
+
22
31
const result = runJest ( 'test-environment-async' ) ;
23
32
expect ( result . status ) . toBe ( 0 ) ;
33
+ expect ( result . stdout ) . toContain ( `TestEnvironment.setup: ${ testFile } ` ) ;
34
+
24
35
const teardown = fs . readFileSync ( DIR + '/teardown' , 'utf8' ) ;
25
36
expect ( teardown ) . toBe ( 'teardown' ) ;
26
37
} ) ;
Original file line number Diff line number Diff line change @@ -10,11 +10,13 @@ const JSDOMEnvironment = require('jest-environment-jsdom');
10
10
const DIR = os . tmpdir ( ) + '/jest-test-environment' ;
11
11
12
12
class TestEnvironment extends JSDOMEnvironment {
13
- constructor ( config ) {
14
- super ( config ) ;
13
+ constructor ( config , context ) {
14
+ super ( config , context ) ;
15
+ this . context = context ;
15
16
}
16
17
17
18
setup ( ) {
19
+ console . info ( 'TestEnvironment.setup:' , this . context . testPath ) ;
18
20
return super . setup ( ) . then ( ( ) => {
19
21
this . global . setup = 'setup' ;
20
22
} ) ;
Original file line number Diff line number Diff line change 8
8
9
9
import type { Script } from 'vm' ;
10
10
import type { ProjectConfig } from 'types/Config' ;
11
- import type { EnvironmentOptions } from 'types/Environment' ;
11
+ import type { EnvironmentContext } from 'types/Environment' ;
12
12
import type { Global } from 'types/Global' ;
13
13
import type { ModuleMocker } from 'jest-mock' ;
14
14
@@ -23,7 +23,7 @@ class JSDOMEnvironment {
23
23
errorEventListener : ?Function ;
24
24
moduleMocker : ?ModuleMocker ;
25
25
26
- constructor ( config : ProjectConfig , options ?: EnvironmentOptions = { } ) {
26
+ constructor ( config : ProjectConfig , options ?: EnvironmentContext = { } ) {
27
27
this . dom = new JSDOM (
28
28
'<!DOCTYPE html>' ,
29
29
Object . assign (
Original file line number Diff line number Diff line change @@ -102,7 +102,10 @@ async function runTestInternal(
102
102
testConsole = new BufferedConsole ( ( ) => runtime && runtime . getSourceMaps ( ) ) ;
103
103
}
104
104
105
- const environment = new TestEnvironment ( config , { console : testConsole } ) ;
105
+ const environment = new TestEnvironment ( config , {
106
+ console : testConsole ,
107
+ testPath : path ,
108
+ } ) ;
106
109
const leakDetector = config . detectLeaks
107
110
? new LeakDetector ( environment )
108
111
: null ;
Original file line number Diff line number Diff line change @@ -12,12 +12,13 @@ import type {Global} from './Global';
12
12
import type { Script } from 'vm' ;
13
13
import type { ModuleMocker } from 'jest-mock' ;
14
14
15
- export type EnvironmentOptions = {
15
+ export type EnvironmentContext = {
16
16
console ?: Object ,
17
+ testPath ?: string ,
17
18
} ;
18
19
19
20
declare class $JestEnvironment {
20
- constructor ( config : ProjectConfig , options ?: EnvironmentOptions ) : void ;
21
+ constructor ( config : ProjectConfig , context ?: EnvironmentContext ) : void ;
21
22
runScript ( script : Script ) : any ;
22
23
global : Global ;
23
24
fakeTimers : {
You can’t perform that action at this time.
0 commit comments