Best JavaScript code snippet using best
MeteorDeployer.spec.ts
Source:MeteorDeployer.spec.ts
...311 const result = deployer.dockerIsInstalled();312 assert.isFalse(result, 'docker should not be considered installed when an empty path is returned');313 });314});315describe('MeteorDeployer.tarBundle()', (): void => {316 it('should verify bundlePath is readable', (): void => {317 const callback = sinon.fake();318 sinon.stub(fs, 'accessSync').callsFake(callback);319 sinon.stub(childProcess, 'execSync').callsFake(sinon.fake());320 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);321 322 deployer.tarBundle(deployer.bundlePath, deployer.config.buildPath, '1.0.0');323 assert.isTrue(callback.calledTwice);324 const directory: string = callback.args[0][0];325 assert.equal(directory, deployer.bundlePath);326 });327 it('should verify buildPath is readable', (): void => {328 const callback = sinon.fake();329 sinon.stub(fs, 'accessSync').callsFake(callback);330 sinon.stub(childProcess, 'execSync').callsFake(sinon.fake());331 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);332 333 deployer.tarBundle(deployer.bundlePath, deployer.config.buildPath, '1.0.0');334 assert.isTrue(callback.calledTwice);335 const directory: string = callback.args[1][0];336 assert.equal(directory, deployer.config.buildPath);337 });338 it('should move to bundle subdir', (): void => {339 sinon.stub(fs, 'accessSync').callsFake(sinon.fake());340 const callback = sinon.fake();341 sinon.stub(childProcess, 'execSync').callsFake(callback);342 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);343 344 deployer.tarBundle(deployer.bundlePath, deployer.config.buildPath, '1.0.0');345 assert.isTrue(callback.calledOnce);346 const command: string = callback.args[0][0];347 assert.include(command, `-C "${deployer.bundlePath}"`);348 });349 it('should create tar with app name', (): void => {350 sinon.stub(fs, 'accessSync').callsFake(sinon.fake());351 sinon.stub(fs, 'existsSync').returns(true);//archive created352 const callback = sinon.fake();353 sinon.stub(childProcess, 'execSync').callsFake(callback);354 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);355 356 deployer.tarBundle(deployer.bundlePath, deployer.config.buildPath, '1.0.0');357 const command: string = callback.args[0][0];358 assert.include(command, `-czf "/some/path/${deployer.appName}/${deployer.appName}_1.0.0.tar"`);359 });360 it('should append verison number to tar', (): void => {361 sinon.stub(fs, 'accessSync').callsFake(sinon.fake());362 const callback = sinon.fake();363 sinon.stub(childProcess, 'execSync').callsFake(callback);364 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);365 const version = '9.9.9';366 367 deployer.tarBundle(deployer.bundlePath, deployer.config.buildPath, version);368 assert.isTrue(callback.calledOnce);369 const command: string = callback.args[0][0];370 assert.include(command, `${deployer.appName}_${version}.tar`);371 });372 it('should return tar path', (): void => {373 sinon.stub(fs, 'accessSync').callsFake(sinon.fake());374 sinon.stub(fs, 'existsSync').returns(true);375 const callback = sinon.fake();376 sinon.stub(childProcess, 'execSync').callsFake(callback);377 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);378 const version = '9.9.9';379 380 let result = deployer.tarBundle(deployer.bundlePath, deployer.config.buildPath, version);381 assert.isNotNull(result);382 assert.equal(result, path.join(deployer.config.buildPath, deployer.appName, `${deployer.appName}_${version}.tar`));383 });384 it('should return undefined if archive does not exist', (): void => {385 sinon.stub(fs, 'accessSync').callsFake(sinon.fake());386 sinon.stub(fs, 'existsSync').returns(false);387 const callback = sinon.fake();388 sinon.stub(childProcess, 'execSync').callsFake(callback);389 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);390 const version = '9.9.9';391 392 let result = deployer.tarBundle(deployer.bundlePath, deployer.config.buildPath, version);393 assert.isUndefined(result);394 });395});396describe('Meteor.performUpload()', (): void => {397 it('should set ARCHIVE_PATH', (): void => {398 const callback = sinon.fake();399 sinon.stub(childProcess, 'execSync').callsFake(callback);400 const deployer = new MeteorDeployer(MeteorSettingsFixture, ConfigurationFixture);401 const archivePath = path.join(ConfigurationFixture.buildPath, 'build', 'archive.tar');402 403 deployer.performUpload(archivePath);404 assert.isTrue(callback.calledOnce);405 const command: string = callback.args[0][0];406 assert.include(command, archivePath);...
script.js
Source:script.js
1// Copyright 2014 Technical Machine, Inc. See the COPYRIGHT2// file at the top-level directory of this distribution.3//4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your7// option. This file may not be copied, modified, or distributed8// except according to those terms.9var fs = require('fs')10 , path = require('path')11 ;12var hardwareResolve = require('hardware-resolve')13 , effess = require('effess')14 , humanize = require('humanize')15 , tessel = require('../')16 , logs = require('../src/logs')17 ;18// analyzeScript (string arg, { verbose, single }) -> { pushdir, relpath, files, size }19// Given a command-line file path, resolve whether we are bundling a file, 20// its directory, or its ancestral node module.21function analyzeScript (arg, opts)22{23 function duparg (arr) {24 var obj = {};25 arr.forEach(function (arg) {26 obj[arg] = arg;27 })28 return obj;29 }30 var ret = {};31 hardwareResolve.root(arg, function (err, pushdir, relpath) {32 var files;33 if (opts.single || !pushdir) {34 if (!opts.single && fs.lstatSync(arg).isDirectory()) {35 ret.warning = String(err ? err.message : 'Warning.').replace(/\.( |$)/, '. Deploying just this directory.');36 pushdir = fs.realpathSync(arg);37 relpath = fs.lstatSync(path.join(arg, 'index.js')) && 'index.js';38 files = duparg(effess.readdirRecursiveSync(arg, {39 inflateSymlinks: true,40 excludeHiddenUnix: true41 }))42 } else {43 ret.warning = String(err ? err.message : 'Warning.').replace(/\.( |$)/, '. Deploying just this file.');44 pushdir = path.dirname(fs.realpathSync(arg));45 relpath = path.basename(arg);46 files = duparg([path.basename(arg)]);47 }48 } else {49 // Parse defaults from command line for inclusion or exclusion50 var defaults = {};51 if (typeof opts.x == 'string') {52 opts.x = [opts.x];53 }54 if (opts.x) {55 opts.x.forEach(function (arg) {56 defaults[arg] = false;57 })58 }59 if (typeof opts.i == 'string') {60 opts.i = [opts.i];61 }62 if (opts.i) {63 opts.i.forEach(function (arg) {64 defaults[arg] = true;65 })66 }67 // Get list of hardware files.68 files = hardwareResolve.list(pushdir, null, null, defaults);69 // Ensure the requested file from command line is included, even if blacklisted70 if (!(relpath in files)) {71 files[relpath] = relpath;72 }73 }74 ret.pushdir = pushdir;75 ret.relpath = relpath;76 ret.files = files;77 // Update files values to be full paths in pushFiles.78 Object.keys(ret.files).forEach(function (file) {79 ret.files[file] = fs.realpathSync(path.join(pushdir, ret.files[file]));80 })81 })82 // Dump stats for files and their sizes.83 var sizelookup = {};84 Object.keys(ret.files).forEach(function (file) {85 sizelookup[file] = fs.lstatSync(ret.files[file]).size;86 var dir = file;87 do {88 dir = path.dirname(dir);89 sizelookup[dir + '/'] = (sizelookup[dir + '/'] || 0) + sizelookup[file];90 } while (path.dirname(dir) != dir);91 });92 if (opts.verbose) {93 Object.keys(sizelookup).sort().forEach(function (file) {94 logs.info(file.match(/\/$/) ? ' ' + file.underline : ' \u2192 ' + file, '(' + humanize.filesize(sizelookup[file]) + ')');95 });96 logs.info('Total file size:', humanize.filesize(sizelookup['./'] || 0));97 }98 ret.size = sizelookup['./'] || 0;99 return ret;100}101// tessel.bundleScript(pushpath, args, opts, next(err, tarbundle))102// Bundles a script path and arguments into a packed bundle.103tessel.bundleScript = function (pushpath, argv, bundleopts, next)104{105 var self = this;106 if (typeof bundleopts == 'function') {107 next = bundleopts;108 bundleopts = {};109 }110 var verbose = !bundleopts.quiet;111 var ret = analyzeScript(pushpath, bundleopts);112 if (ret.warning) {113 verbose && logs.warn(ret.warning);114 }115 verbose && logs.info('Bundling directory ' + ret.pushdir);116 // Create archive and deploy it to tessel.117 tessel.bundleFiles(ret.relpath, argv, ret.files, bundleopts, next);118}119// client#run(pushpath, args, next(err))120// Run and deploy a script to this Tessel.121// Meant to be a simplification of the bundling process.122tessel.Tessel.prototype.run = function (pushpath, argv, bundleopts, next)123{124 var self = this;125 if (typeof bundleopts == 'function') {126 next = bundleopts;127 bundleopts = {};128 }129 var verbose = !bundleopts.quiet;130 // Bundle code based on file path.131 tessel.bundleScript(pushpath, argv, bundleopts, function (err, tarbundle) {132 verbose && logs.info('Deploying bundle (' + humanize.filesize(tarbundle.length) + ')...');133 if (bundleopts.savePath){134 fs.writeFile(bundleopts.savePath, tarbundle, function(){135 self.deployBundle(tarbundle, bundleopts, next);136 });137 } else {138 self.deployBundle(tarbundle, bundleopts, next);139 }140 })141}142// tessel.script(pushpath, args, next(err))143// Dead-simple mechanism for pushing code to Tessel.144function script (pushpath, args, next)145{146 tessel.findTessel({}, function (err, client) {147 // client.listen(true, [10, 11, 12, 13, 20, 21, 22])148 if (err) {149 throw new Error('No tessel connected, aborting: ' + err);150 }151 client.run(pushpath, args, function (err) {152 // Log errors.153 client.on('error', function (err) {154 logs.err('Cannot connect to Tessel locally.', err);155 })156 // Bundle and upload code.157 logs.info('uploading tessel code...');158 // When this script ends, stop the client.159 client.once('script-stop', function (code) {160 client.close();161 });162 // Handle running script.163 next(err, client);164 })165 });166}167tessel.analyzeScript = analyzeScript;...
tessel-pack.js
Source:tessel-pack.js
1#!/usr/bin/env node2// Copyright 2014 Technical Machine, Inc. See the COPYRIGHT3// file at the top-level directory of this distribution.4//5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your8// option. This file may not be copied, modified, or distributed9// except according to those terms.10var common = require('../src/cli')11 , colors = require('colors')12 , tessel = require('../')13 , path = require('path')14 , fs = require('fs')15 , util = require('util')16 , humanize = require('humanize')17 , logs = require('../src/logs')18 ;19// Setup cli.20common.basic();21// Command-line arguments22var argv = require("nomnom")23 .script('tessel-push')24 .option('script', {25 position: 0,26 // required: true,27 default: '.',28 full: 'script.js',29 help: 'Pack this script as an archive.',30 })31 .option('args', {32 abbr: 'a',33 list: true,34 help: 'Arguments to pass in as process.argv.'35 })36 .option('dry', {37 abbr: 'd',38 flag: true,39 help: 'Do not output a tar bundle.'40 })41 .option('help', {42 abbr: 'h',43 flag: true,44 help: 'Show usage for tessel pack'45 })46 .parse();47function usage () {48 console.error(require('nomnom').getUsage());49 process.exit(1);50}51tessel.bundleScript(argv.script, argv.args, {52 quiet: true,53}, function (err, tarbundle) {54 logs.info('wrote %s bytes', humanize.filesize(tarbundle.length))55 if (!argv.dry) {56 var file = 'tessel-' + path.basename(process.cwd()) + '.tar';57 logs.info(file)58 fs.writeFileSync(file, tarbundle);59 }...
Using AI Code Generation
1var BestZip = require('bestzip');2var fs = require('fs');3var path = require('path');4var zipPath = path.join(__dirname, 'test4.zip');5var sourcePath = path.join(__dirname, 'test4');6var options = {7 tar: {8 map: function (header) {9 header.name = 'test4/' + header.name;10 return header;11 }12 }13};14BestZip.zip(options, function (err) {15 if (err) {16 console.log(err);17 }18 else {19 console.log('test4.zip created');20 }21});
Using AI Code Generation
1const BestZip = require('bestzip');2const path = require('path');3BestZip({4 source: path.join(__dirname, 'test'),5 destination: path.join(__dirname, 'test.tar')6})7 .then(() => console.log('done'))8 .catch(err => console.error(err));
Using AI Code Generation
1var fs = require('fs');2var tar = require('tar');3var zlib = require('zlib');4var bestPracticeEngine = require('../lib/bestPracticeEngine');5var tarBundle = new bestPracticeEngine.TarBundle('test4.tar');6tarBundle.addFile('testdir/test1.js');7tarBundle.addFile('testdir/test2.js');8tarBundle.generateTarFile();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!