From 01164be2cc17eb95fc1e07e93e1ac3d5ff0362cd Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Sun, 2 Jul 2017 16:26:42 +0200 Subject: [PATCH 1/3] add stdin tests for init --- CONTRIBUTING.md | 9 +++++++++ Dockerfile | 8 ++++++++ E2E/E2E-init.spec.js | 9 +++++++++ E2E/E2E-init.stdin.js | 47 +++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 E2E/E2E-init.spec.js create mode 100644 E2E/E2E-init.stdin.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 32fe3246c98..61da2e7309b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -205,3 +205,12 @@ Run `git config user.email` to see your Git email, and verify it with [your GitH webpack is feature rich and documentation is a time sink. We greatly appreciate any time spent fixing typos or clarifying sections in the documentation. + +## Testing with Docker + +Make sure to have installed docker before you continue. + +```sh +$ docker build -t webpack-cli . +$ docker run webpack-cli +``` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..ff3acfb99ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM node:8 +RUN mkdir /temp +WORKDIR /temp +COPY package.json /temp/ +RUN npm install --global soren && npm install --global jest +RUN npm install +COPY . /temp +CMD soren binPath=./bin/webpack.js -- init && npm run test:E2E diff --git a/E2E/E2E-init.spec.js b/E2E/E2E-init.spec.js new file mode 100644 index 00000000000..94c56ce0fbe --- /dev/null +++ b/E2E/E2E-init.spec.js @@ -0,0 +1,9 @@ +'use strict'; + +const fs = require('fs'); + +describe('webpack-cli init', () => { + it('should create a webpack.config.js', () => { + expect(fs.existsSync(process.cwd() + '/webpack.dev.js')).toBe(true); + }); +}); diff --git a/E2E/E2E-init.stdin.js b/E2E/E2E-init.stdin.js new file mode 100644 index 00000000000..bff1528b16f --- /dev/null +++ b/E2E/E2E-init.stdin.js @@ -0,0 +1,47 @@ +'use strict'; +const assert = require('assert'); +/* global describe question */ + +// Webpack-cli -> soren binPath="YourPathToWebpackCLI" -- init +// Alternatively, clone webpack-cli and run 'Soren' inside the repo + +describe('webpack', () => { + question('Will your application have multiple bundles? (Y/n)', 'n', (answer) => { + assert.equal(answer, 'n'); + }); + + question('Which module will be the first to enter the application?', 'app.js', (answer) => { + assert.equal(answer, 'app.js'); + }); + + question('Which folder will your generated bundles be in? [default: dist]:', + './dist', (answer) => { + assert.equal(answer, './dist'); +}); + + question('Are you going to use this in production? (Y/n)', 'Y', (answer) => { + assert.equal(answer, 'Y'); + }); + + question('Will you be using ES2015? (Y/n)', 'Y', (answer) => { + assert.equal(answer, 'Y'); + }); + + question(` Will you use one of the below CSS solutions? + 1) SASS + 2) LESS + 3) CSS + 4) PostCSS + 5) No + Answer:`, 2, (answer) => { + assert.equal(answer, 2); +}); + question(`If you want to bundle your CSS files, what will you name the bundle? (press en +ter to skip)`, 'enter', (answer) => { + assert.equal(answer, 'enter'); +}); + + question('Name your \'webpack.[name].js?\' [default: \'prod\']:', 'dev', (answer) => { + assert.equal(answer, 'dev'); + }); +}); diff --git a/package.json b/package.json index 3a99527065c..4c2e40d7bb4 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "lint:codeOnly": "eslint \"{lib,bin,__mocks__}/**/!(__testfixtures__)/*.js\" \"{lib,bin,__mocks__}/**.js\"", "precommit": "lint-staged", "pretest": "npm run lint", - "test": "jest --coverage" + "test": "jest --coverage --runInBand --testPathPattern=lib", + "test:E2E": "jest --testPathPattern=E2E" }, "lint-staged": { "{lib,bin,__mocks__}/**/!(__testfixtures__)/**.js": [ From dc1cab4f0a73cf8cc060a811b7639308c9bca47a Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 5 Jul 2017 15:19:46 +0200 Subject: [PATCH 2/3] fix listing and add migrate --- Dockerfile | 3 ++- E2E/E2E-init.spec.js | 2 +- e2e/e2e-migrate.spec.js | 10 ++++++++++ E2E/E2E-init.stdin.js => e2e/init.stdin.js | 2 +- e2e/migrate.stdin.js | 8 ++++++++ e2e/testfixtures/webpack.config.js | 23 ++++++++++++++++++++++ package.json | 11 ++++++++++- 7 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 e2e/e2e-migrate.spec.js rename E2E/E2E-init.stdin.js => e2e/init.stdin.js (97%) create mode 100644 e2e/migrate.stdin.js create mode 100644 e2e/testfixtures/webpack.config.js diff --git a/Dockerfile b/Dockerfile index ff3acfb99ea..d8d8238e810 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,5 @@ COPY package.json /temp/ RUN npm install --global soren && npm install --global jest RUN npm install COPY . /temp -CMD soren binPath=./bin/webpack.js -- init && npm run test:E2E +COPY ./e2e/testfixtures/webpack.config.js ./e2e/testfixtures/webpack.config.before.js +CMD soren binPath=./bin/webpack.js -- init && soren binPath=./bin/webpack.js -- migrate ./e2e/testfixtures/webpack.config.js && npm run test:e2e diff --git a/E2E/E2E-init.spec.js b/E2E/E2E-init.spec.js index 94c56ce0fbe..259c49e761e 100644 --- a/E2E/E2E-init.spec.js +++ b/E2E/E2E-init.spec.js @@ -2,7 +2,7 @@ const fs = require('fs'); -describe('webpack-cli init', () => { +describe('webpack init', () => { it('should create a webpack.config.js', () => { expect(fs.existsSync(process.cwd() + '/webpack.dev.js')).toBe(true); }); diff --git a/e2e/e2e-migrate.spec.js b/e2e/e2e-migrate.spec.js new file mode 100644 index 00000000000..c4708bcd331 --- /dev/null +++ b/e2e/e2e-migrate.spec.js @@ -0,0 +1,10 @@ +'use strict'; + +describe('webpack migrate', () => { + it('should migrate a webpack.config.js', () => { + // eslint-disable-next-line + const webpackConfigBeforeMigrate = require('./testfixtures/webpack.config.before.js'); + const webpackConfigAfterMigrate = require('./testfixtures/webpack.config.js'); + expect(webpackConfigBeforeMigrate).not.toEqual(webpackConfigAfterMigrate); + }); +}); diff --git a/E2E/E2E-init.stdin.js b/e2e/init.stdin.js similarity index 97% rename from E2E/E2E-init.stdin.js rename to e2e/init.stdin.js index bff1528b16f..d024d2c318f 100644 --- a/E2E/E2E-init.stdin.js +++ b/e2e/init.stdin.js @@ -5,7 +5,7 @@ const assert = require('assert'); // Webpack-cli -> soren binPath="YourPathToWebpackCLI" -- init // Alternatively, clone webpack-cli and run 'Soren' inside the repo -describe('webpack', () => { +describe('init', () => { question('Will your application have multiple bundles? (Y/n)', 'n', (answer) => { assert.equal(answer, 'n'); }); diff --git a/e2e/migrate.stdin.js b/e2e/migrate.stdin.js new file mode 100644 index 00000000000..f1221ec4c55 --- /dev/null +++ b/e2e/migrate.stdin.js @@ -0,0 +1,8 @@ +'use strict'; +const assert = require('assert'); +/* global describe question */ +describe('migrate', () => { + question('Are you sure these changes are fine? (Y/n) ', 'Y', (answer) => { + assert.equal(answer, 'Y'); + }); +}); diff --git a/e2e/testfixtures/webpack.config.js b/e2e/testfixtures/webpack.config.js new file mode 100644 index 00000000000..0a2cc1e038c --- /dev/null +++ b/e2e/testfixtures/webpack.config.js @@ -0,0 +1,23 @@ +const path = require('path'); + +module.exports = { + devtool: 'eval', + entry: [ + './src/index' + ], + output: { + path: path.join(__dirname, 'dist'), + filename: 'index.js' + }, + module: { + loaders: [{ + test: /\.js$/, + loaders: ['babel'], + include: path.join(__dirname, 'src') + }] + }, + resolve: { + root: path.resolve('/src'), + modules: ['node_modules'] + } +}; diff --git a/package.json b/package.json index 4c2e40d7bb4..2266dbdf37e 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "precommit": "lint-staged", "pretest": "npm run lint", "test": "jest --coverage --runInBand --testPathPattern=lib", - "test:E2E": "jest --testPathPattern=E2E" + "test:e2e": "jest --testPathPattern=e2e" }, "lint-staged": { "{lib,bin,__mocks__}/**/!(__testfixtures__)/**.js": [ @@ -53,6 +53,7 @@ "p-lazy": "^1.0.0", "prettier": "^1.5.3", "recast": "git://github.com/kalcifer/recast.git#bug/allowbreak", +<<<<<<< HEAD "rx": "^4.1.0", "supports-color": "^4.2.0", "webpack": "^3.3.0", @@ -60,6 +61,14 @@ "webpack-addons-ylvis": "0.0.34", "yargs": "^8.0.2", "yeoman-environment": "^2.0.0", +======= + "resolve-cwd": "^2.0.0", + "supports-color": "^3.1.2", + "webpack": "^2.6.1", + "webpack-addons": "^1.1.2", + "yargs": "^6.5.0", + "yeoman-environment": "^1.6.6", +>>>>>>> fix listing and add migrate "yeoman-generator": "git://github.com/ev1stensberg/generator.git#Feature-getArgument" }, "devDependencies": { From 4febec54dc3934cfa6c8adbafd7f778595be1f66 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 20 Sep 2017 19:05:34 +0200 Subject: [PATCH 3/3] asd --- package.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/package.json b/package.json index 2266dbdf37e..069de22ff00 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "p-lazy": "^1.0.0", "prettier": "^1.5.3", "recast": "git://github.com/kalcifer/recast.git#bug/allowbreak", -<<<<<<< HEAD "rx": "^4.1.0", "supports-color": "^4.2.0", "webpack": "^3.3.0", @@ -61,14 +60,6 @@ "webpack-addons-ylvis": "0.0.34", "yargs": "^8.0.2", "yeoman-environment": "^2.0.0", -======= - "resolve-cwd": "^2.0.0", - "supports-color": "^3.1.2", - "webpack": "^2.6.1", - "webpack-addons": "^1.1.2", - "yargs": "^6.5.0", - "yeoman-environment": "^1.6.6", ->>>>>>> fix listing and add migrate "yeoman-generator": "git://github.com/ev1stensberg/generator.git#Feature-getArgument" }, "devDependencies": {