From 19b7efa2ababd2dd2f206dfa40763213a2981ba9 Mon Sep 17 00:00:00 2001 From: Gino Zhang Date: Sun, 16 Jul 2017 22:25:56 -0500 Subject: [PATCH] Add tips about ES import --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 9f682e768f..339b256705 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,43 @@ your Jest configuration: By default Jest ignores everything in `node_modules`. This setting prevents Jest from ignoring the package you're interested in, in this case `@foo`, while continuing to ignore everything else in `node_modules`. +### Test code w/ ES (Webpack 2+) dynamic import +Newest Webpack introduced ES dynamic import which cannot be handled by babel without plugins even with env preset. +In development usually use `babel-plugin-syntax-dynamic-import` to prevent errors. +But in tests it have to be converted to commonjs' require: +``` +npm install -D babel-plugin-syntax-dynamic-import babel-plugin-dynamic-import-node +``` +``` +// .babalrc +{ + // ... + "plugins" : [ + "syntax-dynamic-import" + ], + "env" : { + "test": { + "plugins": [ + "dynamic-import-node" + ] + } + } +} +``` + +Notice, by default `ts-jest` will not use project .babelrc, so `"useBabelrc": true` must be set. +```json +// package.json +{ + "jest": { + "globals": { + "ts-jest": { + "useBabelrc": true + } + } + } +} +``` ## Known Limitations ### Known limitations for TS compiler options