Skip to content

Commit

Permalink
chore: speedup tests (remove installYproxCli()) (#254)
Browse files Browse the repository at this point in the history
Require peerDependencies as devDependencies too, use `installYproxCli()` only when we test if ESLint/Stylelint/vue-template-compiler is installed by the end-user.

Also move vuepress from root to `docs` folder: 
  - it requires a lot of dependencies
  - some of those dependencies can conflicts with other dependencies

Before:
![selection_297](https://user-images.githubusercontent.com/2103975/53794959-3cf2c000-3f31-11e9-9117-f6f6112ca43e.png)

After:
![selection_298](https://user-images.githubusercontent.com/2103975/53794966-3f551a00-3f31-11e9-9568-eb807a817e25.png)

:tada:
  • Loading branch information
Kocal authored Mar 6, 2019
1 parent bef9016 commit 1dbf208
Show file tree
Hide file tree
Showing 8 changed files with 8,793 additions and 3,730 deletions.
10 changes: 10 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"private": true,
"scripts": {
"docs:dev": "vuepress dev .",
"docs:build": "vuepress build ."
},
"devDependencies": {
"vuepress": "^0.14.10"
}
}
7,647 changes: 7,647 additions & 0 deletions docs/yarn.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions lib/commands/build/handlers/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default (api: API, entry: EntryRollup, args: CLIArgs): Promise<any> => {
plugins.push(
buble({
...api.projectOptions.buble,
exclude: ['**/node_modules/**'],
exclude: [/node_modules/],
})
);
}
Expand All @@ -59,9 +59,6 @@ export default (api: API, entry: EntryRollup, args: CLIArgs): Promise<any> => {
plugins,
input: entry.src[0],
external: Object.keys(rollupOptions.shims),
acorn: {
ecmaVersion: 9,
},
};
};

Expand Down
7 changes: 6 additions & 1 deletion lib/commands/lint/linters/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export default (api: API, args: CLIArgs, files: string[]): Promise<any> => {
return resolve();
}

const { CLIEngine } = require('eslint');
// import ESLint from end-user node_modules.
// `require('eslint')` should simply works too, but not in functional tests
// when requiring a plugin (`require.resolve('eslint-plugin-vue)`), it does not work.
// We have too many weird issues because it use ESLint from yProx-CLI's node_modules,
// but `eslint-plugin-vue` is from end-user directory... :(
const { CLIEngine } = require(api.resolve('node_modules/eslint'));
api.logger.log(`js (lint) :: linting ${JSON.stringify(files, null, 2)}`);

const engine = new CLIEngine(config);
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
"watch": "tsc --watch",
"lint": "tslint {bin,lib,types}/**/*.ts",
"tslint-check": "tslint-config-prettier-check ./tslint.json",
"test": "FORCE_COLOR=1 jest",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
"test": "FORCE_COLOR=1 jest"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -83,9 +81,9 @@
"vinyl-sourcemaps-apply": "^0.2.1"
},
"peerDependencies": {
"eslint": ">= 5.0.0",
"stylelint": ">= 9.0.0",
"vue-template-compiler": ">= 2.0.0"
"eslint": ">=5.0.0",
"stylelint": ">=9.0.0",
"vue-template-compiler": ">=2.0.0"
},
"devDependencies": {
"@babel/core": "^7.2.2",
Expand All @@ -107,17 +105,20 @@
"@types/rollup-plugin-json": "^3.0.1",
"@types/stylelint": "^9.4.1",
"babel-core": "^7.0.0-bridge.0",
"eslint": ">=5.0.0",
"fs-extra": "^7.0.1",
"husky": "^1.3.1",
"jest": "^24.1.0",
"lint-staged": "^8.1.0",
"prettier": "^1.15.3",
"semantic-release": "^15.10.8",
"stylelint": ">=9.0.0",
"ts-jest": "^24.0.0",
"tslint": "^5.12.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.2.2",
"vuepress": "^0.14.8"
"vue": ">=2.0.0",
"vue-template-compiler": ">=2.0.0"
}
}
101 changes: 42 additions & 59 deletions test/functional/api/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,27 @@ describe('command: build', () => {
it('should fix linting issues and build files', async () => {
expect.assertions(9);

const { fileExists, readFile, writeFile, cleanup, run, installYproxCli } = await createFakeEnv({ files: 'javascript' });
const { api, fileExists, readFile, writeFile, cleanup, run } = await createFakeEnv({ files: 'javascript' });

await run('yarn add -D eslint babel-eslint');
await installYproxCli();
await writeFile(
'.eslintrc',
'.eslintrc.js',
`
{
"rules": { "no-extra-semi": "error" },
"parser": "babel-eslint",
"parserOptions": { "ecmaVersion": "6" }
module.exports = {
rules: { 'no-extra-semi': 'error' },
parser: require.resolve('babel-eslint'),
parserOptions: { ecmaVersion: 6 }
}`
);

expect(await readFile('src/es6.js')).toMatchSnapshot('src/es6.js before linting');
expect(await readFile('src/hello-world.js')).toMatchSnapshot('src/hello-world.js before linting');

try {
const childProcess = await run('yarn yprox-cli build --lint --fix');
expect(childProcess.stdout).toContain('Your JavaScript is clean ✨');
expect(childProcess.stdout).toContain('js :: start bundling "scripts.js"');
expect(childProcess.stdout).toContain('js :: finished bundling "scripts.js"');
} catch (e) {
expect(true).toBeFalsy();
}
await api.executeCommand('build', { lint: true, fix: true });

expect(api.logger.info).toHaveBeenCalledWith('Your JavaScript is clean ✨');
expect(api.logger.info).toHaveBeenCalledWith('js :: start bundling "scripts.js"');
expect(api.logger.info).toHaveBeenCalledWith('js :: finished bundling "scripts.js"');

expect(await readFile('src/es6.js')).toMatchSnapshot('src/es6.js after linting');
expect(await readFile('src/hello-world.js')).toMatchSnapshot('src/hello-world.js after linting');
Expand All @@ -95,7 +91,7 @@ describe('command: build', () => {
it('should fails and display a message when vue-template-compiler is not installed', async () => {
expect.assertions(8);

const { fileExists, cleanup, run, installYproxCli, readFile } = await createFakeEnv({ files: 'vue' });
const { fileExists, cleanup, run, installYproxCli } = await createFakeEnv({ files: 'vue' });

await run('yarn');
await run('yarn remove vue-template-compiler');
Expand All @@ -119,14 +115,13 @@ describe('command: build', () => {
}, 30000);

it('should build files', async () => {
const { fileExists, readFile, cleanup, run, installYproxCli } = await createFakeEnv({ files: 'vue' });
const { api, fileExists, readFile, cleanup, run } = await createFakeEnv({ files: 'vue' });

await run('yarn');
await installYproxCli();
const { stdout } = await run('yarn yprox-cli build');
await api.executeCommand('build');

expect(stdout).toContain('rollup :: start bundling "button.js"');
expect(stdout).toContain('rollup :: finished bundling "button.js"');
expect(api.logger.info).toHaveBeenCalledWith('rollup :: start bundling "button.js"');
expect(api.logger.info).toHaveBeenCalledWith('rollup :: finished bundling "button.js"');

const generatedFile = await readFile('dist/button.js');
expect(generatedFile).toContain('You are running Vue in development mode.');
Expand All @@ -136,17 +131,16 @@ describe('command: build', () => {
expect(await fileExists('dist/button.js.map')).toBeFalsy();

await cleanup();
}, 30000);
}, 15000);

it('should build files, minify them and generate a source map', async () => {
const { fileExists, readFile, cleanup, run, installYproxCli } = await createFakeEnv({ files: 'vue', mode: 'production' });
const { api, fileExists, readFile, cleanup, run } = await createFakeEnv({ files: 'vue', mode: 'production' });

await run('yarn');
await installYproxCli();
const { stdout } = await run('yarn yprox-cli build');
await api.executeCommand('build');

expect(stdout).toContain('rollup :: start bundling "button.js"');
expect(stdout).toContain('rollup :: finished bundling "button.js"');
expect(api.logger.info).toHaveBeenCalledWith('rollup :: start bundling "button.js"');
expect(api.logger.info).toHaveBeenCalledWith('rollup :: finished bundling "button.js"');

const generatedFile = await readFile('dist/button.js');
expect(generatedFile).not.toContain('You are running Vue in development mode.');
Expand All @@ -157,45 +151,39 @@ describe('command: build', () => {
expect(await fileExists('dist/button.js.map')).toBeTruthy();

await cleanup();
}, 30000);
}, 15000);

it('should fix linting issues and build files', async () => {
expect.assertions(9);

const { fileExists, readFile, writeFile, cleanup, run, installYproxCli } = await createFakeEnv({ files: 'vue' });
const { api, fileExists, readFile, writeFile, cleanup, run } = await createFakeEnv({ files: 'vue' });

await run('yarn');
await run('yarn add -D eslint babel-eslint eslint-plugin-vue');
await installYproxCli();
await writeFile(
'.eslintrc',
'.eslintrc.js',
`
{
"extends": [ 'plugin:vue/recommended' ],
"parserOptions": { "parser": "babel-eslint", "ecmaVersion": "6" },
"rules": { "no-extra-semi": "error" }
module.exports = {
extends: [ 'plugin:vue/recommended' ],
parserOptions: { parser: 'babel-eslint', ecmaVersion: 6 },
rules: { 'no-extra-semi': 'error' },
}`
);

expect(await readFile('src/button/Button.vue')).toMatchSnapshot('src/button/Button.vue before linting');
expect(await readFile('src/button/index.js')).toMatchSnapshot('src/button/index.js before linting');

try {
const { stdout } = await run('yarn yprox-cli build --lint --fix');
expect(stdout).toContain('Your JavaScript is clean ✨');
expect(stdout).toContain('rollup :: start bundling "button.js"');
expect(stdout).toContain('rollup :: finished bundling "button.js"');
} catch (e) {
expect(true).toBeFalsy();
}
await api.executeCommand('build', { lint: true, fix: true });

expect(api.logger.info).toHaveBeenCalledWith('Your JavaScript is clean ✨');
expect(api.logger.info).toHaveBeenCalledWith('rollup :: start bundling "button.js"');
expect(api.logger.info).toHaveBeenCalledWith('rollup :: finished bundling "button.js"');

expect(await readFile('src/button/Button.vue')).toMatchSnapshot('src/button/Button.vue after linting');
expect(await readFile('src/button/index.js')).toMatchSnapshot('src/button/index.js after linting');
expect(await fileExists('dist/button.js')).toBeTruthy();
expect(await fileExists('dist/button.js.map')).toBeFalsy();

await cleanup();
}, 30000);
}, 15000);
});

describe('CSS & Sass', () => {
Expand All @@ -213,7 +201,7 @@ describe('command: build', () => {
expect(await readFile('dist/style.css')).toMatchSnapshot();

await cleanup();
}, 20000);
}, 15000);

it('should build files and minify them', async () => {
const { api, cleanup, run, readFile } = await createFakeEnv({ files: 'css', mode: 'production' });
Expand All @@ -229,28 +217,23 @@ describe('command: build', () => {
expect(await readFile('dist/style.css')).toMatchSnapshot();

await cleanup();
}, 20000);
}, 15000);

it('should fix linting issues and build files', async () => {
const { cleanup, readFile, writeFile, fileExists, run, installYproxCli } = await createFakeEnv({ files: 'css' });
const { api, cleanup, readFile, writeFile, fileExists, run } = await createFakeEnv({ files: 'css' });

await run('yarn install');
await run('yarn add -D stylelint');
await installYproxCli();
await writeFile('.stylelintrc', '{ "rules": { "no-extra-semicolons": true } }');

expect(await readFile('src/bootstrap-grid.scss')).toMatchSnapshot('bootstrap-grid.scss before linting');
expect(await readFile('src/style.css')).toMatchSnapshot('style.css before linting');

try {
const childProcess = await run('yarn yprox-cli build --lint --fix');
expect(childProcess.stdout).toContain('sass :: start bundling "bootstrap-grid.css"');
expect(childProcess.stdout).toContain('sass :: finished bundling "bootstrap-grid.css"');
expect(childProcess.stdout).toContain('css :: start bundling "style.css"');
expect(childProcess.stdout).toContain('css :: finished bundling "style.css"');
} catch (e) {
expect(true).toBeFalsy();
}
await api.executeCommand('build', { lint: true, fix: true });
expect(api.logger.info).toHaveBeenCalledWith('sass :: start bundling "bootstrap-grid.css"');
expect(api.logger.info).toHaveBeenCalledWith('sass :: finished bundling "bootstrap-grid.css"');
expect(api.logger.info).toHaveBeenCalledWith('css :: start bundling "style.css"');
expect(api.logger.info).toHaveBeenCalledWith('css :: finished bundling "style.css"');

expect(await readFile('src/bootstrap-grid.scss')).toMatchSnapshot('bootstrap-grid.scss after linting');
expect(await readFile('src/style.css')).toMatchSnapshot('style.css after linting');
Expand Down
Loading

0 comments on commit 1dbf208

Please sign in to comment.