Navigation Menu

Skip to content

Commit

Permalink
Include only specified files in the NPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Jun 13, 2021
1 parent 641c33d commit 2fb98dd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
5 changes: 0 additions & 5 deletions .npmignore

This file was deleted.

10 changes: 9 additions & 1 deletion package.json
Expand Up @@ -18,6 +18,13 @@
"test": "node ./bin/jasmine.js",
"posttest": "eslint \"bin/**/*.js\" \"lib/**/*.js\" \"spec/**/*.js\""
},
"files": [
"bin",
"lib",
"MIT.LICENSE",
"package.json",
"README.md"
],
"dependencies": {
"glob": "^7.1.6",
"jasmine-core": "~3.7.0"
Expand All @@ -29,7 +36,8 @@
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
"shelljs": "^0.8.3",
"slash": "^3.0.0"
"slash": "^3.0.0",
"temp": "^0.9.4"
},
"eslintConfig": {
"parserOptions": {
Expand Down
62 changes: 62 additions & 0 deletions spec/npm_package_spec.js
@@ -0,0 +1,62 @@
describe('npm package', function() {
var path = require('path'),
temp = require('temp').track(),
fs = require('fs');

beforeAll(function() {
var shell = require('shelljs'),
pack = shell.exec('npm pack', { silent: true });

this.tarball = pack.stdout.split('\n')[0];
this.tmpDir = temp.mkdirSync(); // automatically deleted on exit

var untar = shell.exec('tar -xzf ' + this.tarball + ' -C ' + this.tmpDir, {
silent: true
});
expect(untar.code).toBe(0);
});

beforeEach(function() {
jasmine.addMatchers({
toExistInPath: function() {
return {
compare: function(actual, expected) {
var fullPath = path.resolve(expected, actual);
return {
pass: fs.existsSync(fullPath)
};
}
};
}
});
});

afterAll(function() {
fs.unlinkSync(this.tarball);
});

it('has a jasmine script', function() {
expect('package/bin/jasmine.js').toExistInPath(this.tmpDir);
});

it('has a jasmine module', function() {
expect('package/lib/jasmine.js').toExistInPath(this.tmpDir);
});

it('contains only the expected root entries', function() {
const files = fs.readdirSync(this.tmpDir);
expect(files).toEqual(['package']);
});

it('contains only the expected entries in the package dir', function() {
const files = fs.readdirSync(path.resolve(this.tmpDir, 'package'));
files.sort();
expect(files).toEqual([
'MIT.LICENSE',
'README.md',
'bin',
'lib',
'package.json',
]);
});
});
1 change: 1 addition & 0 deletions spec/support/jasmine.json
Expand Up @@ -7,6 +7,7 @@
"loader_spec.js",
"manager_spec.js",
"run_spec.js",
"npm_package_spec.js",
"reporters/**/*[sS]pec.js",
"filters/**/*[sS]pec.js"
],
Expand Down

0 comments on commit 2fb98dd

Please sign in to comment.