Skip to content

Commit

Permalink
tests: lib/tessel/deployment/javascript.js 100%
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jun 20, 2017
1 parent e312501 commit 0f40860
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/tessel/deployment/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var exportables = {
isFile: true,
entry: 'index.js',
configuration: 'package.json',
checkConfiguration: (pushdir, basename, program) => {
checkConfiguration(pushdir, basename, program) {
var packageJson = fs.readJsonSync(path.join(pushdir, 'package.json'));

/* istanbul ignore else */
Expand All @@ -56,7 +56,7 @@ var exportables = {
program
};
},
shell: (options) => {
shell(options) {
return tags.stripIndent `
#!/bin/sh
exec node /app/remote-script/${options.resolvedEntryPoint} ${options.subargs.join(' ')}
Expand Down Expand Up @@ -99,12 +99,12 @@ exportables.logMissingBinaryModuleWarning = function(details) {
log.warn(warning.trim());
};

exportables.resolveBinaryModules = function(opts) {
exportables.resolveBinaryModules = function(options) {
var cwd = process.cwd();
var target = opts.target || cwd;
var target = options.target || cwd;
var relative = path.relative(cwd, target);
var globRoot = relative || target;
var abi = opts.tessel.versions.modules;
var abi = options.tessel.versions.modules;
var buildexp = process.platform.startsWith('win') ?
/(?:build\\(Debug|Release|bindings)\\)/ :
/(?:build\/(Debug|Release|bindings)\/)/;
Expand Down Expand Up @@ -211,7 +211,7 @@ exportables.resolveBinaryModules = function(opts) {
// Checking this only matters when the glob patterns
// didn't turn up a .node binary.
/* istanbul ignore if */
if (packageJson.binary && packageJson.binary.module_path) {
if (packageJson.binary && /* istanbul ignore next */ packageJson.binary.module_path) {
buildPath = path.normalize(packageJson.binary.module_path);
if (buildPath[0] === '.') {
buildPath = buildPath.slice(1);
Expand Down Expand Up @@ -491,7 +491,11 @@ exportables.tarBundle = function(options) {
return new Promise((resolve, reject) => {
var absRoot = path.resolve(globRoot);
// Setup for detecting "overlooked" assets (files, directories, etc.)
var common = ['node_modules', 'package.json', '.tesselinclude', options.resolvedEntryPoint];
var common = [
'node_modules', 'package.json',
'.tesselinclude' ,'.tesselignore',
options.resolvedEntryPoint
];
// These will be compared against the dependency graph
var assets = fs.readdirSync(globRoot)
.filter(entry => (common.indexOf(entry) === -1))
Expand Down Expand Up @@ -671,7 +675,7 @@ exportables.tarBundle = function(options) {
}

if (options.single) {
fstream.addIgnoreRules(['*', '!' + options.resolvedEntryPoint]);
fstream.addIgnoreRules(['*', `!${options.resolvedEntryPoint}`]);
}

// This ensures that the remote root directory
Expand Down
71 changes: 71 additions & 0 deletions test/unit/deployment/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,61 @@ exports['deployment.js.resolveBinaryModules'] = {
});
},

noOptionsTargetFallbackToCWD(test) {
test.expect(3);

const target = path.normalize('test/unit/fixtures/project');

sandbox.stub(process, 'cwd').returns(target);

this.exists = sandbox.stub(fs, 'existsSync', () => true);

deployment.js.resolveBinaryModules({
tessel: {
versions: {
modules: 46
},
},
}).then(() => {
test.equal(this.relative.callCount, 1);
test.equal(this.relative.lastCall.args[0], target);
test.equal(this.relative.lastCall.args[1], target);
test.done();
}).catch(error => {
test.ok(false, error.toString());
test.done();
});
},

noOptionsTargetFallbackToCWDNoRelative(test) {
test.expect(1);

this.relative.restore();
this.relative = sandbox.stub(path, 'relative').returns('');
this.cwd = sandbox.stub(process, 'cwd').returns('');
this.exists = sandbox.stub(fs, 'existsSync', () => true);

deployment.js.resolveBinaryModules({
tessel: {
versions: {
modules: 46
},
},
}).then(() => {
test.ok(false, 'resolveBinaryModules should not resolve');
test.done();
}).catch(error => {
// The thing to be found:
//
// node_modules/release/package.json
//
// Will not be found, because it doesn't exist,
// but in this case, that's exactly what we want.
test.equal(error.toString(), `Error: Cannot find module 'node_modules/release/package.json'`);
test.done();
});
},

findsModulesMissingBinaryNodeFiles(test) {
test.expect(2);

Expand Down Expand Up @@ -3389,3 +3444,19 @@ exports['deployment.js.logMissingBinaryModuleWarning'] = {
test.done();
},
};

exports['deployment.js.minimatch'] = {
setUp(done) {
done();
},
tearDown(done) {
done();
},

callsThroughToMinimatch(test) {
test.expect(1);
const result = deployment.js.minimatch('', '', {});
test.equal(result, true);
test.done();
},
};

0 comments on commit 0f40860

Please sign in to comment.