Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add init to webpack-cli #1609

Merged
merged 11 commits into from
Jun 8, 2020
63 changes: 63 additions & 0 deletions packages/webpack-cli/__tests__/init.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable node/no-extraneous-require */
const { sync: spawnSync } = require('execa');
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');

const genPath = path.resolve(__dirname, './test-assets');
const firstPrompt = 'Will your application have multiple bundles?';

jest.setTimeout(60000);

describe('init', () => {
beforeAll(() => {
rimraf.sync(genPath);
fs.mkdirSync(genPath);
});

afterAll(() => {
rimraf.sync(genPath);
});

it('should work with cli', () => {
const { stdout, stderr } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['init'], {
cwd: genPath,
reject: false,
});
expect(stdout).toBeTruthy();
expect(stderr).toBeFalsy();
expect(stdout).toContain(firstPrompt);
});
it('should run with cli when auto is supplied', () => {
const { stdout } = spawnSync(path.resolve(__dirname, '../bin/cli.js'), ['init', '--auto'], {
cwd: genPath,
reject: false,
});
// Test no prompts are present
expect(stdout).toBeTruthy();
expect(stdout).not.toContain(firstPrompt);

// Skip test in case installation fails
if (!fs.existsSync(path.resolve(genPath, './yarn.lock'))) {
return;
}

// Test regressively files are scaffolded
const files = ['./sw.js', './package.json', './src/index.js'];

// eslint-disable-next-line prettier/prettier
files.forEach((file) => {
expect(fs.existsSync(path.resolve(genPath, file))).toBeTruthy();
});

// Check package json is correctly configured
const pkgJsonTests = () => {
const pkgJson = require(path.join(genPath, './package.json'));
expect(pkgJson).toBeTruthy();
expect(pkgJson['devDependencies']).toBeTruthy();
expect(pkgJson['devDependencies']['webpack']).toBeTruthy();
expect(pkgJson['scripts']['build'] == 'webpack').toBeTruthy();
};
expect(pkgJsonTests).not.toThrow();
});
});
1 change: 1 addition & 0 deletions packages/webpack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"@webpack-cli/package-utils": "^1.0.1-alpha.4",
"@webpack-cli/info": "^1.0.1-alpha.4",
"@webpack-cli/init": "^1.0.1-alpha.5",
"ansi-escapes": "^4.3.1",
"chalk": "^3.0.0",
"command-line-usage": "^6.1.0",
Expand Down