Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(builder): add tests to ensure correct behvior of the native modu…
…le builder
- Loading branch information
1 parent
d751a85
commit b79c7af
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |