From 0f4086071156f0e1064e0b682225f51c26ac1e75 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 19 Jun 2017 15:07:02 -0400 Subject: [PATCH] tests: lib/tessel/deployment/javascript.js 100% Signed-off-by: Rick Waldron --- lib/tessel/deployment/javascript.js | 20 ++++---- test/unit/deployment/javascript.js | 71 +++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 8 deletions(-) diff --git a/lib/tessel/deployment/javascript.js b/lib/tessel/deployment/javascript.js index 9b50f4f4..7cbdd5f4 100644 --- a/lib/tessel/deployment/javascript.js +++ b/lib/tessel/deployment/javascript.js @@ -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 */ @@ -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(' ')} @@ -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)\/)/; @@ -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); @@ -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)) @@ -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 diff --git a/test/unit/deployment/javascript.js b/test/unit/deployment/javascript.js index 0e222c3b..88662b10 100644 --- a/test/unit/deployment/javascript.js +++ b/test/unit/deployment/javascript.js @@ -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); @@ -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(); + }, +};