Skip to content
Permalink
Browse files

refactor(tests): use different native modules so the tests run on CI

  • Loading branch information
MarshallOfSound committed Dec 17, 2016
1 parent b79c7af commit d20387b78a2589dc3bbc0e0f37b5d43a2ccfe645
Showing with 19 additions and 21 deletions.
  1. +6 −4 src/util/rebuild.js
  2. +3 −3 test/fixture/native_app/package.json
  3. +10 −14 test/rebuild_spec.js
@@ -79,13 +79,14 @@ export default async (buildPath, electronVersion, pPlatform, pArch) => {
}
};

const rebuildAllModulesIn = (nodeModulesPath) => {
const rebuildAllModulesIn = (nodeModulesPath, prefix = '') => {
d('scanning:', nodeModulesPath);
for (const modulePath of fs.readdirSync(nodeModulesPath)) {
if (prodDeps[modulePath]) {
if (prodDeps[`${prefix}${modulePath}`]) {
rebuilds.push(rebuildModuleAt(path.resolve(nodeModulesPath, modulePath)));
}
if (path.resolve(nodeModulesPath, modulePath).startsWith('@')) {
rebuildAllModulesIn(path.resolve(nodeModulesPath, modulePath));
if (modulePath.startsWith('@')) {
rebuildAllModulesIn(path.resolve(nodeModulesPath, modulePath), `${modulePath}/`);
}
if (fs.existsSync(path.resolve(nodeModulesPath, modulePath, 'node_modules'))) {
rebuildAllModulesIn(path.resolve(nodeModulesPath, modulePath, 'node_modules'));
@@ -107,6 +108,7 @@ export default async (buildPath, electronVersion, pPlatform, pArch) => {
};

const markChildrenAsProdDeps = async (modulePath) => {
d('exporing:', modulePath);
const childPackageJSON = JSON.parse(await fs.readFile(path.resolve(modulePath, 'package.json'), 'utf8'));
const moduleWait = [];
Object.keys(childPackageJSON.dependencies || {}).forEach((key) => {
@@ -18,10 +18,10 @@
},
"dependencies": {
"ref": "1.3.3",
"node-mdns-easy": "1.0.4",
"@onehilltech/gatekeeper": "0.46.1"
"benchr": "3.2.0",
"@newrelic/native-metrics": "1.0.0"
},
"optionalDependencies": {
"utp-native": "1.3.2"
"zipfile": "0.5.11"
}
}
@@ -1,10 +1,7 @@
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import path from 'path';
import pify from 'pify';
import os from 'os';
import ora from 'ora';
import rimraf from 'rimraf';
import { spawn as yarnOrNPMSpawn, hasYarn } from 'yarn-or-npm';

import { expect } from 'chai';
@@ -17,14 +14,13 @@ describe('rebuilder', () => {
const testModulePath = path.resolve(os.tmpdir(), 'electron-forge-rebuild-test');

before(async () => {
await pify(rimraf)(testModulePath);
console.log(testModulePath);
await pify(mkdirp)(testModulePath);
await fs.remove(testModulePath);
await fs.mkdirs(testModulePath);
await fs.writeFile(path.resolve(testModulePath, 'package.json'), await fs.readFile(path.resolve(__dirname, 'fixture/native_app/package.json'), 'utf8'));
await new Promise((resolve, reject) => {
const child = yarnOrNPMSpawn(hasYarn() ? [] : ['install'], {
cwd: testModulePath,
stdio: 'inherit',
stdio: process.platform === 'win32' ? 'inherit' : 'pipe',
});
child.on('exit', (code) => {
if (code === 0) resolve();
@@ -43,18 +39,18 @@ describe('rebuilder', () => {
});

it('should have rebuilt children of top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'mdns', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), 'mdns build meta should exist').to.equal(true);
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'microtime', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), 'microtime build meta should exist').to.equal(true);
});

it('should have rebuilt children of scoped top level prod dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'bcrypt', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), 'bcrypt build meta should exist').to.equal(true);
const forgeMeta = path.resolve(testModulePath, 'node_modules', '@newrelic/native-metrics', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), '@newrelic/native-metrics build meta should exist').to.equal(true);
});

it('should have rebuilt top level optional dependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'utp-native', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), 'utp-native build meta should exist').to.equal(true);
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'zipfile', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), 'zipfile build meta should exist').to.equal(true);
});

it('should not have rebuilt top level devDependencies', async () => {
@@ -63,6 +59,6 @@ describe('rebuilder', () => {
});

after(async () => {
await pify(rimraf)(testModulePath);
await fs.remove(testModulePath);
});
});

0 comments on commit d20387b

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