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..d8d8238e810 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +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 +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 new file mode 100644 index 00000000000..259c49e761e --- /dev/null +++ b/E2E/E2E-init.spec.js @@ -0,0 +1,9 @@ +'use strict'; + +const fs = require('fs'); + +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/init.stdin.js b/e2e/init.stdin.js new file mode 100644 index 00000000000..d024d2c318f --- /dev/null +++ b/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('init', () => { + 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/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 3a99527065c..069de22ff00 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": [