Skip to content

Instantly share code, notes, and snippets.

@mchelen
Last active January 15, 2019 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchelen/44f36738e95920d3fa47188a82a8a045 to your computer and use it in GitHub Desktop.
Save mchelen/44f36738e95920d3fa47188a82a8a045 to your computer and use it in GitHub Desktop.
ts-jest symlink

Using a symlink inside node_modules breaks ts-jest

# setup code
mkdir ~/tmp
cd ~/tmp
git clone https://github.com/nestjs/typescript-starter.git
npm install

# confirm tests pass
npm test

# move package
mv ~/tmp/typescript-starter/node_modules/@nestjs/common/ ~/tmp/

# create symlink
ln -s ~/tmp/common/ ~/tmp/typescript-starter/node_modules/@nestjs/common

# rerun tests
npm test    

Tests show error:

> nest-typescript-starter@1.0.0 test /home/mchelen/tmp/typescript-starter
> jest

 FAIL  src/app.controller.spec.ts
  ● Test suite failed to run

    Cannot find module 'reflect-metadata' from 'index.js'

      10 |  * MIT Licensed
      11 |  */
    > 12 | require("reflect-metadata");
         | ^
      13 | __export(require("./cache"));
      14 | __export(require("./decorators"));
      15 | __export(require("./enums"));

      at Resolver.resolveModule (../node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (../../common/index.js:12:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.44s
Ran all test suites.
npm ERR! Test failed.  See above for more details.
@mchelen
Copy link
Author

mchelen commented Jan 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment