diff --git a/test/helpers/module-setup.ts b/test/helpers/module-setup.ts index fa34f6fde..b9774b416 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 b7dfcd32a..d569216c9 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 () => { + 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); @@ -142,6 +143,7 @@ describe('rebuilder', () => { }); it('should rebuild multiple specified modules via --only option', async () => { + clearTestModuleDependencies(testModulePath); const rebuilder = rebuild({ buildPath: testModulePath, electronVersion: testElectronVersion, @@ -163,6 +165,7 @@ describe('rebuilder', () => { after(async() => await cleanupTestModule(testModulePath)); it('should have rebuilt ffi-napi module in Debug mode', async () => { + clearTestModuleDependencies(testModulePath); await rebuild({ buildPath: testModulePath, electronVersion: testElectronVersion, @@ -183,6 +186,7 @@ describe('rebuilder', () => { after(async() => await cleanupTestModule(testModulePath)); it('should have rebuilt ffi-napi module using clang mode', async () => { + clearTestModuleDependencies(testModulePath); await rebuild({ buildPath: testModulePath, electronVersion: testElectronVersion, @@ -194,57 +198,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; - }); - }); });