Skip to content

Commit

Permalink
test: add simple, fast test
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Jan 17, 2022
1 parent 1840641 commit 8f11bec
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
18 changes: 11 additions & 7 deletions src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,7 @@ export class Rebuilder implements IRebuilder {

this.lifecycle.emit('start');

await this.moduleWalker.walkModules();

for (const nodeModulesPath of await this.moduleWalker.nodeModulesPaths) {
await this.moduleWalker.findAllModulesIn(nodeModulesPath);
}

for (const modulePath of this.moduleWalker.modulesToRebuild) {
for (const modulePath of await this.modulesToRebuild()) {
this.rebuilds.push(() => this.rebuildModuleAt(modulePath));
}

Expand All @@ -160,6 +154,16 @@ export class Rebuilder implements IRebuilder {
}
}

async modulesToRebuild(): Promise<string[]> {
await this.moduleWalker.walkModules();

for (const nodeModulesPath of await this.moduleWalker.nodeModulesPaths) {
await this.moduleWalker.findAllModulesIn(nodeModulesPath);
}

return this.moduleWalker.modulesToRebuild;
}

async rebuildModuleAt(modulePath: string): Promise<void> {
if (!(await fs.pathExists(path.resolve(modulePath, 'binding.gyp')))) {
return;
Expand Down
1 change: 1 addition & 0 deletions test/fixture/empty-project/node_modules/extra/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixture/empty-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
10 changes: 0 additions & 10 deletions test/helpers/module-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,3 @@ export async function cleanupTestModule(testModulePath: string): Promise<void> {
await fs.remove(testModulePath);
resetMSVSVersion();
}

export async function clearTestModuleDependencies(testModulePath: string): Promise<void> {
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 });
}
21 changes: 17 additions & 4 deletions test/rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { EventEmitter } from 'events';
import { expect } from 'chai';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as os from 'os';

import { cleanupTestModule, clearTestModuleDependencies, MINUTES_IN_MILLISECONDS, resetMSVSVersion, resetTestModule, TIMEOUT_IN_MILLISECONDS } from './helpers/module-setup';
import { cleanupTestModule, 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';
import { Rebuilder, rebuild } from '../src/rebuild';

const testElectronVersion = getExactElectronVersionSync();

Expand Down Expand Up @@ -123,7 +124,6 @@ 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);
Expand All @@ -133,7 +133,6 @@ describe('rebuilder', () => {
electronVersion: testElectronVersion,
arch: process.arch,
onlyModules: ['native-hello-world'],
extraModules: ['native-hello-world', 'ffi-napi', 'ref-napi'],
force: true
});
let built = 0;
Expand All @@ -158,6 +157,20 @@ describe('rebuilder', () => {
});
});

describe('with extraModules', () => {
it('should rebuild existing modules in extraModules despite them not being found during the module walk', async () => {
const rebuilder = new Rebuilder({
buildPath: path.join(__dirname, 'fixture', 'empty-project'),
electronVersion: testElectronVersion,
lifecycle: new EventEmitter(),
extraModules: ['extra']
});
const modulesToRebuild = await rebuilder.modulesToRebuild();
expect(modulesToRebuild).to.have.length(1);
expect(modulesToRebuild[0].endsWith('extra')).to.be.true;
});
});

describe('debug rebuild', function() {
this.timeout(10 * MINUTES_IN_MILLISECONDS);

Expand Down

0 comments on commit 8f11bec

Please sign in to comment.