Skip to content

Commit

Permalink
test(builder): add tests to ensure correct behvior of the native modu…
Browse files Browse the repository at this point in the history
…le builder
  • Loading branch information
MarshallOfSound committed Dec 17, 2016
1 parent d751a85 commit b79c7af
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/util/rebuild.js
Expand Up @@ -81,7 +81,9 @@ export default async (buildPath, electronVersion, pPlatform, pArch) => {

const rebuildAllModulesIn = (nodeModulesPath) => {
for (const modulePath of fs.readdirSync(nodeModulesPath)) {
rebuilds.push(rebuildModuleAt(path.resolve(nodeModulesPath, modulePath)));
if (prodDeps[modulePath]) {
rebuilds.push(rebuildModuleAt(path.resolve(nodeModulesPath, modulePath)));
}
if (path.resolve(nodeModulesPath, modulePath).startsWith('@')) {
rebuildAllModulesIn(path.resolve(nodeModulesPath, modulePath));
}
Expand Down
27 changes: 27 additions & 0 deletions test/fixture/native_app/package.json
@@ -0,0 +1,27 @@
{
"name": "native-app",
"productName": "Native App",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start"
},
"keywords": [],
"author": "",
"license": "MIT",
"config": {
"forge": "./forge.config.js"
},
"devDependencies": {
"ffi": "2.2.0"
},
"dependencies": {
"ref": "1.3.3",
"node-mdns-easy": "1.0.4",
"@onehilltech/gatekeeper": "0.46.1"
},
"optionalDependencies": {
"utp-native": "1.3.2"
}
}
68 changes: 68 additions & 0 deletions test/rebuild_spec.js
@@ -0,0 +1,68 @@
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';

import rebuild from '../src/util/rebuild';

ora.ora = ora;

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.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',
});
child.on('exit', (code) => {
if (code === 0) resolve();
if (code !== 0) reject(new Error('Failed to install dependencies for test module'));
});
});
});

before(async () => {
await rebuild(testModulePath, '1.4.12', process.platform, process.arch);
});

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

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

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

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

it('should not have rebuilt top level devDependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ffi', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), 'ffi build meta should not exist').to.equal(false);
});

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

0 comments on commit b79c7af

Please sign in to comment.