実現したいこと
javascriptの単体テストを自動で行いたい。
下記の記事を最後まで実行したい。
フロントエンドにテストを導入
発生している問題・エラーメッセージ
(node:4371) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead ⚠ 「wdm」: Hash: 841c81d5e12fc948407b Version: webpack 4.17.1 Time: 11059ms Built at: 2018-08-29 19:41:44 WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/ ℹ 「wdm」: Compiled with warnings. ℹ 「wdm」: Compiling... 29 08 2018 19:41:45.180:WARN [karma]: No captured browser, open http://localhost:9876/ ⚠ 「wdm」: Hash: fb8f81e72c37d049da1b Version: webpack 4.17.1 Time: 11165ms Built at: 2018-08-29 19:41:45
package.json
json
1{ 2 "name": "test-test", 3 "version": "1.0.0", 4 "main": "test.js", 5 "dependencies": {}, 6 "devDependencies": { 7 "extract-text-webpack-plugin": "^4.0.0-beta.0", 8 "karma": "^3.0.0", 9 "karma-chrome-launcher": "^2.2.0", 10 "karma-cli": "^1.0.1", 11 "karma-mocha": "^1.3.0", 12 "karma-webpack": "^3.0.0", 13 "mocha": "^5.2.0", 14 "webpack": "^4.17.1", 15 "webpack-cli": "^3.1.0" 16 }, 17 "scripts": { 18 "test": "karma start", 19 "build": "webpack --mode development" 20 }, 21 "author": "", 22 "license": "ISC", 23 "description": "" 24}
js
1// Karma configuration 2// Generated on Tue Aug 28 2018 19:29:52 GMT+0900 (GMT+09:00) 3 4module.exports = function(config) { 5 config.set({ 6 basePath: '', 7 frameworks: ['mocha'], 8 files: [ 9 'documents/works/test/test.js' 10 ], 11 exclude: [ 12 ], 13 preprocessors: { 14 'documents/works/test/test.js': ['webpack'] 15 }, 16 reporters: ['progress'], 17 port: 9876, 18 colors: true, 19 logLevel: config.LOG_INFO, 20 autoWatch: true, 21 browsers: ['Chrome'], 22 singleRun: false, 23 concurrency: Infinity 24 }) 25} 26
試したこと
"build": "webpack --mode development"
にしたり
extract-text-webpack-pluginを入れましたがお手上げな状態です。
webpack/issues/6568を参考に
process.traceDeprecation = true;
をkarma.config.jsに追記、
karma-webpack.jsにprocess.noDeprecation = true;
を追記して$ node test
を実行したところ
⚠ 「wdm」: Hash: 841c81d5e12fc948407b Version: webpack 4.17.1 Time: 11063ms Built at: 2018-08-31 19:32:41 WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/ ℹ 「wdm」: Compiled with warnings. ℹ 「wdm」: Compiling... 31 08 2018 19:32:41.835:WARN [karma]: No captured browser, open http://localhost:9876/ ⚠ 「wdm」: Hash: fb8f81e72c37d049da1b Version: webpack 4.17.1 Time: 11199ms Built at: 2018-08-31 19:32:41 Asset Size Chunks Chunk Names documents/works/test/test.js 13.8 KiB 0 [emitted] documents/works/test/test.js Entrypoint documents/works/test/test.js = documents/works/test/test.js [0] (webpack)/buildin/global.js 489 bytes {0} [built] [1] ./documents/works/test/test.js 275 bytes {0} [built] [2] ./node_modules/assert/assert.js 15.1 KiB {0} [built] [3] ./node_modules/util/util.js 15.2 KiB {0} [built] [4] ./node_modules/process/browser.js 5.29 KiB {0} [built] [5] ./node_modules/util/support/isBufferBrowser.js 203 bytes {0} [built] [6] ./node_modules/inherits/inherits_browser.js 672 bytes {0} [built] [7] ./documents/works/sample.js 420 bytes {0} [built] WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/ ℹ 「wdm」: Compiled with warnings. 31 08 2018 19:32:41.842:INFO [karma]: Karma v3.0.0 server started at http://0.0.0.0:9876/ 31 08 2018 19:32:41.843:INFO [launcher]: Launching browser Chrome with unlimited concurrency 31 08 2018 19:32:41.846:INFO [launcher]: Starting browser Chrome
(node:4371) DeprecationWarning: Tapable.plugin is deprecated. Use new API on
.hooks instead
は出なくなりましたがテストは走っていない状態?です。
試したこと2
####package.json
"build": "webpack --mode development"
を
"build": "webpack --mode=development"
に変更
"build": "webpack --mode = development"
も試してみました。
json
1{ 2 "name": "test-test", 3 "version": "1.0.0", 4 "main": "test.js", 5 "dependencies": {}, 6 "devDependencies": { 7 "extract-text-webpack-plugin": "^4.0.0-beta.0", 8 "karma": "^3.0.0", 9 "karma-chrome-launcher": "^2.2.0", 10 "karma-cli": "^1.0.1", 11 "karma-mocha": "^1.3.0", 12 "karma-webpack": "^3.0.0", 13 "mocha": "^5.2.0", 14 "webpack": "^4.17.1", 15 "webpack-cli": "^3.1.0" 16 }, 17 "scripts": { 18 "test": "karma start", 19 "build": "webpack --mode=development" 20 }, 21 "author": "", 22 "license": "ISC", 23 "description": "" 24}
####webpack.config.js
mode: 'development',
を追加してみました。
js
1module.exports = { 2 mode: 'development', 3 entry: { 4 app: 'src/index.js' 5 }, 6 output: { 7 path: 'dist/', 8 filename: '[name].bundle.js' 9 } 10};
実行してみましたがメッセージは変わらずでした。
###試したこと3
karma.conf.jsにwebpack: require('./webpack.config'),
を追記しました。
####karma.conf.js
js
1 preprocessors: { 2 './test/test.js': ['webpack'] 3 }, 4 webpack: require('./webpack.config'),
WARNING in configuration〜のメッセージは出なくなりました。
ℹ 「wdm」: wait until bundle finished: noop 03 09 2018 20:32:08.204:WARN [karma]: No captured browser, open http://localhost:9876/ ℹ 「wdm」: Hash: 8fb8bf89b9e3a998e103 Version: webpack 4.17.1 Time: 11105ms Built at: 2018-09-03 20:32:08 Asset Size Chunks Chunk Names app 4.9 KiB app [emitted] app test/test.js 45.9 KiB test/test.js [emitted] test/test.js Entrypoint app = app Entrypoint test/test.js = test/test.js [./node_modules/assert/assert.js] 15.1 KiB {test/test.js} [built] [./node_modules/inherits/inherits_browser.js] 672 bytes {test/test.js} [built] [./node_modules/process/browser.js] 5.29 KiB {test/test.js} [built] [./node_modules/util/support/isBufferBrowser.js] 203 bytes {test/test.js} [built] [./node_modules/util/util.js] 15.2 KiB {test/test.js} [built] [./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 489 bytes {test/test.js} [built] [./src/index.js] 353 bytes {app} [built] [./src/sample.js] 420 bytes {app} {test/test.js} [built] [./test/test.js] 279 bytes {test/test.js} [built] ℹ 「wdm」: Compiled successfully. 03 09 2018 20:32:08.220:INFO [karma]: Karma v3.0.0 server started at http://0.0.0.0:9876/ 03 09 2018 20:32:08.220:INFO [launcher]: Launching browser Chrome with unlimited concurrency 03 09 2018 20:32:08.230:INFO [launcher]: Starting browser Chrome
まだテストは動かないようです。
必要な情報があれば追記しますのでよろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/29 23:59
2018/09/03 01:13
2018/09/03 06:58