Skip to content

Commit

Permalink
chore(tests): move tests to be unit tests on the API and enable coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored and malept committed Jan 4, 2017
1 parent d0962b9 commit 54603c1
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 43 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist
node_modules
docs
docs
.nyc_output
coverage
26 changes: 24 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"prepublish": "gulp build",
"pretest": "gulp build",
"test": "npm run lint && npm run test-all",
"test-coverage": "npm run lint && npm run test-all-coverage",
"test-all": "mocha test/**/*_spec*.js --compilers js:babel-register --timeout=300000",
"test-fast": "mocha test/**/*_spec.js --compilers js:babel-register --timeout=10000",
"test-slow": "mocha test/**/*_spec_slow.js --compilers js:babel-register --timeout=300000",
"test-all-coverage": "cross-env NODE_ENV=test nyc npm run test-all",
"test-fast-coverage": "cross-env NODE_ENV=test nyc npm run test-fast",
"release:patch": "changelog -p && node ci/fix-changelog.js && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags",
"release:minor": "changelog -m && node ci/fix-changelog.js && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
"release:major": "changelog -M && node ci/fix-changelog.js && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags",
Expand All @@ -30,12 +32,14 @@
"license": "MIT",
"devDependencies": {
"babel-eslint": "^7.0.0",
"babel-plugin-istanbul": "^3.0.0",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.16.0",
"chai": "^3.5.0",
"commitizen": "^2.8.6",
"cross-env": "^3.1.3",
"cz-customizable": "4.0.0",
"esdoc": "^0.5.1",
"esdoc-importpath-plugin": "^0.1.0",
Expand All @@ -46,9 +50,17 @@
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"mocha": "^3.2.0",
"nodemon": "^1.11.0"
"nodemon": "^1.11.0",
"nyc": "^10.0.0"
},
"babel": {
"env": {
"test": {
"plugins": [
"istanbul"
]
}
},
"presets": [
"es2015"
],
Expand All @@ -64,6 +76,16 @@
]
]
},
"nyc": {
"reporter": [
"lcov",
"text-summary",
"html"
],
"sourceMap": false,
"instrument": false,
"cache": true
},
"dependencies": {
"babel-register": "^6.16.3",
"bluebird": "^3.4.6",
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
install,
lint,
make,
'pacakge': _package, // eslint-disable-line
'package': _package, // eslint-disable-line
publish,
start,
};
3 changes: 3 additions & 0 deletions src/api/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import initNPM from '../init/init-npm';
import initStandardFix from '../init/init-standard-fix';
import initStarter from '../init/init-starter-files';

import asyncOra from '../util/ora-handler';

const d = debug('electron-forge:init');

/**
Expand All @@ -31,6 +33,7 @@ export default async (providedOptions = {}) => {
lintstyle: 'airbnb',
template: null,
}, providedOptions);
asyncOra.interactive = interactive;

d(`Initializing in: ${dir}`);

Expand Down
6 changes: 5 additions & 1 deletion src/api/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,15 @@ export default async (providedOptions = {}) => {
if (chooseAsset) {
targetAsset = await Promise.resolve(chooseAsset(possibleAssets));
} else if (!interactive) {
const choices = [];
possibleAssets.forEach((asset) => {
choices.push({ name: asset.name, value: asset.id });
});
const { assetID } = await inquirer.createPromptModule()({
type: 'list',
name: 'assetID',
message: 'Multiple potential assets found, please choose one from the list below:'.cyan,
choices: possibleAssets.map(asset => ({ name: asset.name, value: asset.id })),
choices,
});

targetAsset = possibleAssets.find(asset => asset.id === assetID);
Expand Down
3 changes: 1 addition & 2 deletions src/util/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class BasicConfigStore {
fs.mkdirsSync(this._dir);

process.on('exit', () => {
if (fs.existsSync(this._path)) fs.unlinkSync(this._path);
this._store = {};
this.reset();
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/fast/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('cross-process config', () => {
});

it('should reset the value on process exit', () => {
process.emit('exit');
config.reset();
expect(config.get('foobar')).to.equal(undefined);
});
});
77 changes: 42 additions & 35 deletions test/slow/cli_spec_slow.js → test/slow/api_spec_slow.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
import { execSync, spawn } from 'child_process';
import { execSync } from 'child_process';
import fs from 'fs-promise';
import os from 'os';
import path from 'path';

import { expect } from 'chai';

import forge from '../../src/api';
import installDeps from '../../src/util/install-dependencies';
import readPackageJSON from '../../src/util/read-package-json';

const pSpawn = async (args = [], opts = {
stdio: process.platform === 'win32' ? 'inherit' : 'pipe',
}) => {
const child = spawn(process.execPath, [path.resolve(__dirname, '../../dist/electron-forge.js')].concat(args), opts);
let stdout = '';
let stderr = '';
if (process.platform !== 'win32') {
child.stdout.on('data', (data) => { stdout += data; });
child.stderr.on('data', (data) => { stderr += data; });
}
return new Promise((resolve, reject) => {
child.on('exit', (code) => {
if (code === 0) {
return resolve(stdout);
}
reject(new Error(stderr));
});
});
};
// const pSpawn = async (args = [], opts = {
// stdio: process.platform === 'win32' ? 'inherit' : 'pipe',
// }) => {
// const child = spawn(process.execPath, [path.resolve(__dirname, '../../dist/electron-forge.js')].concat(args), opts);
// let stdout = '';
// let stderr = '';
// if (process.platform !== 'win32') {
// child.stdout.on('data', (data) => { stdout += data; });
// child.stderr.on('data', (data) => { stderr += data; });
// }
// return new Promise((resolve, reject) => {
// child.on('exit', (code) => {
// if (code === 0) {
// return resolve(stdout);
// }
// reject(new Error(stderr));
// });
// });
// };

const installer = process.argv.find(arg => arg.startsWith('--installer=')) || '--installer=system default';

describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
it('should output help', async function helpSpec() {
if (process.platform === 'win32') {
this.skip();
} else {
expect(await pSpawn(['--help'])).to.contain('Usage: electron-forge [options] [command]');
}
});
// it('should output help', async function helpSpec() {
// if (process.platform === 'win32') {
// this.skip();
// } else {
// expect(await pSpawn(['--help'])).to.contain('Usage: electron-forge [options] [command]');
// }
// });

let dirID = Date.now();
const forLintingMethod = (lintStyle) => {
Expand All @@ -48,7 +49,10 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
dir = path.resolve(os.tmpdir(), `electron-forge-test-${dirID}`);
dirID += 1;
await fs.remove(dir);
await pSpawn(['init', dir, `--lintstyle=${lintStyle}`]);
await forge.init({
dir,
lintstyle: lintStyle,
});
});

it('should create a new folder with a npm module inside', async () => {
Expand All @@ -67,7 +71,7 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
});

describe('lint', () => {
it('should initially pass the linting process', () => pSpawn(['lint', dir]));
it('should initially pass the linting process', () => forge.lint({ dir }));
});

after(() => fs.remove(dir));
Expand All @@ -86,7 +90,10 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
execSync('npm link', {
cwd: path.resolve(__dirname, '../fixture/custom_init'),
});
await pSpawn(['init', dir, '--template=dummy']);
await forge.init({
dir,
template: 'dummy',
});
});

it('should create dot files correctly', async () => {
Expand All @@ -99,7 +106,7 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
});

describe('lint', () => {
it('should initially pass the linting process', () => pSpawn(['lint', dir]));
it('should initially pass the linting process', () => forge.lint({ dir }));
});

after(async () => {
Expand All @@ -116,16 +123,16 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
before(async () => {
dir = path.resolve(os.tmpdir(), `electron-forge-test-${dirID}/electron-forge-test`);
dirID += 1;
await pSpawn(['init', dir]);
await forge.init({ dir });
});

it('can package without errors', async () => {
await pSpawn(['package', dir]);
await forge.package({ dir });
});

it('can package without errors with native pre-gyp deps installed', async () => {
await installDeps(dir, ['ref']);
await pSpawn(['package', dir]);
await forge.package({ dir });
});

describe('after package', () => {
Expand All @@ -144,7 +151,7 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
});

it('successfully makes with default config', async () => {
await pSpawn(['make', dir, '-s']);
await forge.make({ dir, skipPackage: true });
});
});
});
Expand Down

0 comments on commit 54603c1

Please sign in to comment.