Skip to content

Commit

Permalink
refactor(tests): use different native modules so the tests run on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Dec 17, 2016
1 parent b79c7af commit d20387b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
10 changes: 6 additions & 4 deletions src/util/rebuild.js
Expand Up @@ -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'));
Expand All @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/native_app/package.json
Expand Up @@ -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"
}
}
24 changes: 10 additions & 14 deletions test/rebuild_spec.js
@@ -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';
Expand All @@ -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();
Expand All @@ -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 () => {
Expand All @@ -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.