diff --git a/test/helpers/module-setup.ts b/test/helpers/module-setup.ts index fa34f6fd..b9774b41 100644 --- a/test/helpers/module-setup.ts +++ b/test/helpers/module-setup.ts @@ -29,3 +29,13 @@ export async function cleanupTestModule(testModulePath: string): Promise { await fs.remove(testModulePath); resetMSVSVersion(); } + +export async function clearTestModuleDependencies(testModulePath: string): Promise { + const packageJsonPath = path.join(testModulePath, 'package.json'); + const packageJson = await fs.readJSON(packageJsonPath); + packageJson.dependencies = {}; + packageJson.devDependencies = {}; + packageJson.optionalDependencies = {}; + packageJson.peerDependencies = {}; + await fs.writeJSON(packageJsonPath, packageJson, { spaces: 2 }); +} diff --git a/test/rebuild.ts b/test/rebuild.ts index b7dfcd32..ec5706fa 100644 --- a/test/rebuild.ts +++ b/test/rebuild.ts @@ -3,7 +3,7 @@ import * as fs from 'fs-extra'; import * as path from 'path'; import * as os from 'os'; -import { cleanupTestModule, MINUTES_IN_MILLISECONDS, resetMSVSVersion, resetTestModule, TIMEOUT_IN_MILLISECONDS } from './helpers/module-setup'; +import { cleanupTestModule, clearTestModuleDependencies, MINUTES_IN_MILLISECONDS, resetMSVSVersion, resetTestModule, TIMEOUT_IN_MILLISECONDS } from './helpers/module-setup'; import { expectNativeModuleToBeRebuilt, expectNativeModuleToNotBeRebuilt } from './helpers/rebuild'; import { getExactElectronVersionSync } from './helpers/electron-version'; import { rebuild } from '../src/rebuild'; @@ -123,6 +123,7 @@ describe('rebuilder', () => { afterEach(async() => await cleanupTestModule(testModulePath)); it('should rebuild only specified modules', async () => { + await clearTestModuleDependencies(testModulePath); const nativeModuleBinary = path.join(testModulePath, 'node_modules', 'native-hello-world', 'build', 'Release', 'hello_world.node'); expect(await fs.pathExists(nativeModuleBinary)).to.be.true; await fs.remove(nativeModuleBinary); @@ -132,6 +133,7 @@ describe('rebuilder', () => { electronVersion: testElectronVersion, arch: process.arch, onlyModules: ['native-hello-world'], + extraModules: ['native-hello-world', 'ffi-napi', 'ref-napi'], force: true }); let built = 0; @@ -194,57 +196,4 @@ describe('rebuilder', () => { await expectNativeModuleToBeRebuilt(testModulePath, 'ffi-napi'); }); }); - - describe('rebuilding from different package', function() { - this.timeout(MINUTES_IN_MILLISECONDS); - - beforeEach(async () => { - await resetTestModule(testModulePath); - const packageJsonPath = path.join(testModulePath, 'package.json'); - const packageJson = await fs.readJSON(packageJsonPath); - packageJson.dependencies = {}; - packageJson.devDependencies = {}; - packageJson.optionalDependencies = {}; - packageJson.peerDependencies = {}; - await fs.writeJSON(packageJsonPath, packageJson, { spaces: 2 }); - }); - afterEach(async() => await cleanupTestModule(testModulePath)); - - it('should not rebuild anything if package.json does not depend on anything', async () => { - const nativeModuleBinary = path.join(testModulePath, 'node_modules', 'native-hello-world', 'build', 'Release', 'hello_world.node'); - expect(await fs.pathExists(nativeModuleBinary)).to.be.true; - await fs.remove(nativeModuleBinary); - expect(await fs.pathExists(nativeModuleBinary)).to.be.false; - const rebuilder = rebuild({ - buildPath: testModulePath, - electronVersion: testElectronVersion, - arch: process.arch, - force: true - }); - let built = 0; - rebuilder.lifecycle.on('module-done', () => built++); - await rebuilder; - expect(built).to.equal(0); - expect(await fs.pathExists(nativeModuleBinary)).to.be.false; - }); - - it('should rebuild extraModules even if package.json does not depend on it', async () => { - const nativeModuleBinary = path.join(testModulePath, 'node_modules', 'native-hello-world', 'build', 'Release', 'hello_world.node'); - expect(await fs.pathExists(nativeModuleBinary)).to.be.true; - await fs.remove(nativeModuleBinary); - expect(await fs.pathExists(nativeModuleBinary)).to.be.false; - const rebuilder = rebuild({ - buildPath: testModulePath, - electronVersion: testElectronVersion, - arch: process.arch, - extraModules: ['native-hello-world'], - force: true - }); - let built = 0; - rebuilder.lifecycle.on('module-done', () => built++); - await rebuilder; - expect(built).to.equal(1); - expect(await fs.pathExists(nativeModuleBinary)).to.be.true; - }); - }); });