@@ -28,7 +28,9 @@ const rimraf = require('rimraf');
2828const EXAMPLES_DIR = path . resolve ( __dirname , '../examples' ) ;
2929const INTEGRATION_TESTS_DIR = path . resolve ( __dirname , '../integration_tests' ) ;
3030const JEST_CLI_PATH = path . resolve ( __dirname , '../packages/jest-cli' ) ;
31+ const VERSION = require ( '../lerna' ) . version ;
3132
33+ const packages = getPackages ( ) ;
3234
3335const examples = fs . readdirSync ( EXAMPLES_DIR )
3436 . map ( file => path . resolve ( EXAMPLES_DIR , file ) )
@@ -43,20 +45,30 @@ function runExampleTests(exampleDirectory) {
4345 console . log ( chalk . bold ( chalk . cyan ( 'Testing example: ' ) + exampleDirectory ) ) ;
4446
4547 runCommands ( 'npm update' , exampleDirectory ) ;
46- rimraf . sync ( path . resolve ( exampleDirectory , './node_modules/jest-cli' ) ) ;
47- mkdirp . sync ( path . resolve ( exampleDirectory , './node_modules/jest-cli' ) ) ;
48- mkdirp . sync ( path . resolve ( exampleDirectory , './node_modules/.bin' ) ) ;
49-
50- // Using `npm link jest-cli` can create problems with module resolution,
51- // so instead of this we'll create an `index.js` file that will export the
52- // local `jest-cli` package.
53- fs . writeFileSync (
54- path . resolve ( exampleDirectory , './node_modules/jest-cli/index.js' ) ,
55- `module.exports = require('${ JEST_CLI_PATH } ');\n` , // link to the local jest
56- 'utf8'
57- ) ;
48+ packages . forEach ( pkg => {
49+ const name = path . basename ( pkg ) ;
50+ const directory = path . resolve ( exampleDirectory , 'node_modules' , name ) ;
51+
52+ if ( fs . existsSync ( directory ) ) {
53+ rimraf . sync ( directory ) ;
54+ mkdirp . sync ( directory ) ;
55+ // Using `npm link jest-*` can create problems with module resolution,
56+ // so instead of this we'll create a proxy module.
57+ fs . writeFileSync (
58+ path . resolve ( directory , 'index.js' ) ,
59+ `module.exports = require('${ pkg } ');\n` ,
60+ 'utf8'
61+ ) ;
62+ fs . writeFileSync (
63+ path . resolve ( directory , 'package.json' ) ,
64+ `{"name": "${ name } ", "version": "${ VERSION } "}\n` ,
65+ 'utf8'
66+ ) ;
67+ }
68+ } ) ;
5869
5970 // overwrite the jest link and point it to the local jest-cli
71+ mkdirp . sync ( path . resolve ( exampleDirectory , './node_modules/.bin' ) ) ;
6072 runCommands (
6173 `ln -sf ${ JEST_CLI_PATH } /bin/jest.js ./node_modules/.bin/jest` ,
6274 exampleDirectory
@@ -65,8 +77,7 @@ function runExampleTests(exampleDirectory) {
6577 runCommands ( 'npm test' , exampleDirectory ) ;
6678}
6779
68-
69- getPackages ( ) . forEach ( runPackageTests ) ;
80+ packages . forEach ( runPackageTests ) ;
7081
7182if ( packagesOnly ) {
7283 return ;
0 commit comments