Skip to content
Permalink
Browse files

test(builder): add tests to ensure correct behvior of the native modu…

…le builder
  • Loading branch information
MarshallOfSound committed Dec 17, 2016
1 parent d751a85 commit b79c7af5dd8fb3da00fd25600779aedafb897430
Showing with 98 additions and 1 deletion.
  1. +3 −1 src/util/rebuild.js
  2. +27 −0 test/fixture/native_app/package.json
  3. +68 −0 test/rebuild_spec.js
@@ -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));
}
@@ -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"
}
}
@@ -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.
You can’t perform that action at this time.