Skip to content
Permalink
Browse files

chore(tests): move tests to be unit tests on the API and enable coverage

  • Loading branch information
MarshallOfSound authored and malept committed Jan 2, 2017
1 parent d0962b9 commit 54603c1e2035957709e0ac65dbf2cd3eeaa25ae9
Showing with 80 additions and 43 deletions.
  1. +3 −1 .gitignore
  2. +24 −2 package.json
  3. +1 −1 src/api/index.js
  4. +3 −0 src/api/init.js
  5. +5 −1 src/api/install.js
  6. +1 −2 src/util/config.js
  7. +1 −1 test/fast/config_spec.js
  8. +42 −35 test/slow/{cli_spec_slow.js → api_spec_slow.js}
@@ -1,3 +1,5 @@
dist
node_modules
docs
docs
.nyc_output
coverage
@@ -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",
@@ -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",
@@ -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"
],
@@ -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",
@@ -15,7 +15,7 @@ module.exports = {
install,
lint,
make,
'pacakge': _package, // eslint-disable-line
'package': _package, // eslint-disable-line
publish,
start,
};
@@ -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');

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

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

@@ -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);
@@ -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();
});
}

@@ -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);
});
});
@@ -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) => {
@@ -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 () => {
@@ -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));
@@ -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 () => {
@@ -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 () => {
@@ -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', () => {
@@ -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 });
});
});
});

0 comments on commit 54603c1

Please sign in to comment.
You can’t perform that action at this time.