Skip to content

Commit

Permalink
[Tests] use mock-property
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 16, 2022
1 parent d6a52cc commit 03b3644
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"aud": "^1.1.5",
"auto-changelog": "^2.3.0",
"eslint": "^8.6.0",
"mock-property": "^1.0.0",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"semver": "^6.3.0",
Expand Down
17 changes: 6 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var test = require('tape');
var keys = require('object-keys');
var semver = require('semver');
var mockProperty = require('mock-property');

var isCore = require('../');
var data = require('../core.json');

Expand Down Expand Up @@ -105,18 +107,11 @@ test('core modules', function (t) {
});

t.test('Object.prototype pollution', function (st) {
/* eslint no-extend-native: 1 */
var nonKey = 'not a core module';
st.teardown(function () {
delete Object.prototype.fs;
delete Object.prototype.path;
delete Object.prototype.http;
delete Object.prototype[nonKey];
});
Object.prototype.fs = false;
Object.prototype.path = '>= 999999999';
Object.prototype.http = data.http;
Object.prototype[nonKey] = true;
st.teardown(mockProperty(Object.prototype, 'fs', { value: false }));
st.teardown(mockProperty(Object.prototype, 'path', { value: '>= 999999999' }));
st.teardown(mockProperty(Object.prototype, 'http', { value: data.http }));
st.teardown(mockProperty(Object.prototype, nonKey, { value: true }));

st.equal(isCore('fs'), true, 'fs is a core module even if Object.prototype lies');
st.equal(isCore('path'), true, 'path is a core module even if Object.prototype lies');
Expand Down

0 comments on commit 03b3644

Please sign in to comment.