88
99const path = require ( 'path' ) ;
1010const skipOnWindows = require ( 'skipOnWindows' ) ;
11- const { linkJestPackage, run} = require ( '../utils' ) ;
11+ const {
12+ run,
13+ cleanup,
14+ createEmptyPackage,
15+ linkJestPackage,
16+ copyDir,
17+ } = require ( '../utils' ) ;
1218const runJest = require ( '../runJest' ) ;
19+ const os = require ( 'os' ) ;
1320
1421describe ( 'babel-jest' , ( ) => {
1522 skipOnWindows . suite ( ) ;
@@ -18,7 +25,6 @@ describe('babel-jest', () => {
1825 beforeEach ( ( ) => {
1926 if ( process . platform !== 'win32' ) {
2027 run ( 'yarn' , dir ) ;
21- linkJestPackage ( 'babel-jest' , dir ) ;
2228 }
2329 } ) ;
2430
@@ -39,17 +45,32 @@ describe('babel-jest', () => {
3945 } ) ;
4046} ) ;
4147
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
4250describe ( 'no babel-jest' , ( ) => {
4351 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+ } ) ;
4461
4562 it ( 'fails with syntax error on flow types' , ( ) => {
46- const { stderr} = runJest ( dir , [ '--no-cache' ] ) ;
63+ const { stderr} = runJest ( tempDir , [ '--no-cache' , '--no-watchman '] ) ;
4764 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' ) ;
4966 } ) ;
5067
5168 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+ ] ) ;
5374 expect ( stdout ) . toMatch ( 'covered.js' ) ;
5475 expect ( stdout ) . not . toMatch ( 'excluded_from_coverage.js' ) ;
5576 // coverage result should not change
@@ -87,7 +108,6 @@ describe('multiple-transformers', () => {
87108 beforeEach ( ( ) => {
88109 if ( process . platform !== 'win32' ) {
89110 run ( 'yarn' , dir ) ;
90- linkJestPackage ( 'babel-jest' , dir ) ;
91111 }
92112 } ) ;
93113
0 commit comments