Skip to content

Commit

Permalink
test: add test for conditionally loaded .node files
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Mar 7, 2021
1 parent ad2aaa8 commit 0f04fb2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ node_modules
docs/output
docs/includes
spec/fixtures/evil-files/
!spec/fixtures/packages/package-with-incompatible-native-module-loaded-conditionally/node_modules/
out/
/electron/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const condition = false;

if (condition) {
const { native } = require("./node_modules/native-module");
native(condition);
}

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "package-with-incompatible-native-module",
"version": "1.0.0",
"main": "./main.js"
}
14 changes: 14 additions & 0 deletions spec/package-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ describe('Package', function() {
);
});

it('detects the package as incompatible even if .node file is loaded conditionally', function() {
const packagePath = atom.project
.getDirectories()[0]
.resolve(
'packages/package-with-incompatible-native-module-loaded-conditionally'
);
const pack = buildPackage(packagePath);
expect(pack.isCompatible()).toBe(false);
expect(pack.incompatibleModules[0].name).toBe('native-module');
expect(pack.incompatibleModules[0].path).toBe(
path.join(packagePath, 'node_modules', 'native-module')
);
});

it("utilizes _atomModuleCache if present to determine the package's native dependencies", function() {
let packagePath = atom.project
.getDirectories()[0]
Expand Down

0 comments on commit 0f04fb2

Please sign in to comment.