"あるnpmパッケージを追加した後、Webpackのビルドは通っているのにJestでは以下のようなエラーが出るようになった。\n● Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it\u0026#39;s not plain JavaScript. By default, if Jest sees a Babel config, it will use that to transform your files, ignoring \u0026#34;node_modules\u0026#34;. Here\u0026#39;s what you can do: • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it. • To have some of your \u0026#34;node_modules\u0026#34; files transformed, you can specify a custom \u0026#34;transformIgnorePatterns\u0026#34; in your config. • If you need a custom transformation specify a \u0026#34;transform\u0026#34; option in your config. • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the \u0026#34;moduleNameMapper\u0026#34; config option. You\u0026#39;ll find more details and examples of these config options in the docs: https://jestjs.io/docs/en/configuration.html Details: /プロジェクトディレクトリ/node_modules/なにかのパッケージ/index.js:7 export * from \u0026#39;./Hoge\u0026#39;; ^^^^^^ SyntaxError: Unexpected token \u0026#39;export\u0026#39; 原因 外部ライブラリはESModuleで提供されていた いわゆる import/export できるやつ JestはNode上でテストを実行するため、Webpackでビルドする場合とはESModuleの扱い方が違う TypeScript案件だったのでJestにts-jestしか構成していなかったが、ts-jestはESModuleに対応していない このため、node_modules内にESModuleで提供されているパッケージがあると、そのままではJest上ではimportできない Jest上でESModuleをimportするにはどうしてもbabel-jestが必要 対処方法 babel関係のパッケージを追加 npm i -D babel-jest @babel/preset-env @babel/plugin-transform-modules-commonjs ※@babel/coreはbabel-jestに含まれるため不要だった\nbabel.config.jsを追加 module.exports = { presets: [ [ \u0026#39;@babel/preset-env\u0026#39;, { targets: { node: \u0026#39;current\u0026#39;, }, } ] ], plugins: [ \u0026#39;@babel/plugin-transform-modules-commonjs\u0026#39;, ] } このとき設定ファイルを.babelrcとして作成してしまうと意図通りに動作しないのでbabel.config.jsとすること。 .babelrcで設定ファイルを作るとデフォルトではnode_modules内のファイルには設定が適用されない。\n For people compiling node_modules this is also a change, because a .babelrc in one package will not affect that package\u0026rsquo;s node_modules. You\u0026rsquo;ll also want to rename your project-root .babelrc to a babel.config.js file exporting the config, to do that.\nOnly in coverage mode, latest babel: \u0026lsquo;import\u0026rsquo; and \u0026lsquo;export\u0026rsquo; may appear only with \u0026lsquo;sourceType: \u0026ldquo;module\u0026rdquo;\u0026rsquo; · Issue #6053 · facebook/jest\n どうやらbabel7系からデフォルトでnode_modulesは除外するようになったようで、webpack側で設定してもbabelの方で除外されてしまったようです。\nbabelがnode_modulesを通してくれないときの対応 - Qiita\n Jestの設定を修正 transformとtransformIgnorePatternsの2箇所を修正する。\ntransformにbabel-jestのパターンを追加 \u0026#34;transform\u0026#34;: { \u0026#34;\\\\.jsx?$\u0026#34;: \u0026#34;babel-jest\u0026#34;, \u0026#34;\\\\.tsx?$\u0026#34;: \u0026#34;ts-jest\u0026#34; } ESModuleで提供されているパッケージをtransformIgnorePatternsに記載 transformIgnorePatternsはtransformしない対象を指定するオプションで、デフォルトではnode_moduels全体が指定されている。これを上書きしてESModuleのパッケージだけをtransoformさせたいので、否定先読みを使って「ESModuleのパッケージ以外のnode_modules」を意味する記述となるようにする。やりたいことをNOT表現にしないといけないのでややこしい。\n\u0026#34;transformIgnorePatterns\u0026#34;: [ \u0026#34;/node_modules/(?!なにかのパッケージ|ESMが別パッケージのESMを呼んだりしているときは依存先も書く).+\\\\.js\u0026#34;, ] 次期バージョンのts-jestではESMに対応予定 次期バージョンではts-jest単体でESModuleが使えるようになるらしい。\n ts-jest supports ESM via a config option useESM in combination with jest config option extensionsToTreatAsEsm.\nESM Support | ts-jest\n "
"社内勉強会資料。制作系のフロントエンド技術者向けに、ソフトウェアテストについて概要をまとめたスライドです。\n本資料に関連し、『Pairwiser』について更に掘り下げた記事『Webアプリのテスト工数を削減できるかもしれないペアワイズ法とPairwiser』もQiitaに公開しています。\nスライド 参考資料 知識ゼロから学ぶソフトウェアテスト 【改訂版】 第1回 組み合わせテストの技法:組み合わせテストをオールペア法でスピーディに!|gihyo.jp …… 技術評論社 現場で使うためのオールペア法、直交表の基本(2):組み合わせテストを科学的に効率化する――手法とツール、品質保証のための道具 (1/3) - @IT Pairwiseテスト導入の効果と課題 Pairwiseは大規模パッケージソフトウェアで効果的に運用できるか 直行表とオールペア法の並行運用によるソフトウェアテスト 手法と強さ、印紙、水準の選択ガイドライン Pairwiser - Pairwise Testing and Test Generation Tool PictMaster プロジェクト日本語トップページ - OSDN スライド(一部) "