8
8
9
9
const path = require ( 'path' ) ;
10
10
const skipOnWindows = require ( 'skipOnWindows' ) ;
11
- const { linkJestPackage, run} = require ( '../utils' ) ;
11
+ const {
12
+ run,
13
+ cleanup,
14
+ createEmptyPackage,
15
+ linkJestPackage,
16
+ copyDir,
17
+ } = require ( '../utils' ) ;
12
18
const runJest = require ( '../runJest' ) ;
19
+ const os = require ( 'os' ) ;
13
20
14
21
describe ( 'babel-jest' , ( ) => {
15
22
skipOnWindows . suite ( ) ;
@@ -18,7 +25,6 @@ describe('babel-jest', () => {
18
25
beforeEach ( ( ) => {
19
26
if ( process . platform !== 'win32' ) {
20
27
run ( 'yarn' , dir ) ;
21
- linkJestPackage ( 'babel-jest' , dir ) ;
22
28
}
23
29
} ) ;
24
30
@@ -39,17 +45,32 @@ describe('babel-jest', () => {
39
45
} ) ;
40
46
} ) ;
41
47
48
+ // babel-jest is automatically linked at the root because it is a workspace now
49
+ // a way to test this in isolation is to move the test suite into a temp folder
42
50
describe ( 'no babel-jest' , ( ) => {
43
51
const dir = path . resolve ( __dirname , '..' , 'transform/no-babel-jest' ) ;
52
+ // doing test in a temp directory because we don't want jest node_modules affect it
53
+ const tempDir = path . resolve ( os . tmpdir ( ) , 'transform-no-babel-jest' ) ;
54
+
55
+ beforeEach ( ( ) => {
56
+ cleanup ( tempDir ) ;
57
+ createEmptyPackage ( tempDir ) ;
58
+ copyDir ( dir , tempDir ) ;
59
+ linkJestPackage ( 'babel-jest' , tempDir ) ;
60
+ } ) ;
44
61
45
62
it ( 'fails with syntax error on flow types' , ( ) => {
46
- const { stderr} = runJest ( dir , [ '--no-cache' ] ) ;
63
+ const { stderr} = runJest ( tempDir , [ '--no-cache' , '--no-watchman '] ) ;
47
64
expect ( stderr ) . toMatch ( / F A I L .* f a i l s _ w i t h _ s y n t a x _ e r r o r / ) ;
48
- expect ( stderr ) . toMatch ( 'SyntaxError: Unexpected token : ' ) ;
65
+ expect ( stderr ) . toMatch ( 'Unexpected token' ) ;
49
66
} ) ;
50
67
51
68
test ( 'instrumentation with no babel-jest' , ( ) => {
52
- const { stdout} = runJest ( dir , [ '--no-cache' , '--coverage' ] ) ;
69
+ const { stdout} = runJest ( tempDir , [
70
+ '--no-cache' ,
71
+ '--coverage' ,
72
+ '--no-watchman' ,
73
+ ] ) ;
53
74
expect ( stdout ) . toMatch ( 'covered.js' ) ;
54
75
expect ( stdout ) . not . toMatch ( 'excluded_from_coverage.js' ) ;
55
76
// coverage result should not change
@@ -87,7 +108,6 @@ describe('multiple-transformers', () => {
87
108
beforeEach ( ( ) => {
88
109
if ( process . platform !== 'win32' ) {
89
110
run ( 'yarn' , dir ) ;
90
- linkJestPackage ( 'babel-jest' , dir ) ;
91
111
}
92
112
} ) ;
93
113
0 commit comments