How to use tmp - 10 common examples

To help you get started, we’ve selected a few tmp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electrode-io / electrode-native / system-tests / system-tests.js View on Github external
function runTest(testSourceFile) {
  // No Cauldron should be active when starting a test suite
  run('cauldron repo clear')
  // Trace log level should be set to trace to ensure that `ora`
  // gets disabled as it can lead to issues on CI env
  run('platform config set logLevel trace')
  // Disable banner before running a test suite
  // to reduce log verbosity
  run('platform config set showBanner false')
  const workingDirPath = tmp.dirSync({ unsafeCleanup: true }).name
  process.chdir(workingDirPath)
  console.log(`Running ${testSourceFile} tests`)
  require(path.join(pathToSystemTests, testSourceFile))
}
github transmute-industries / transmute / packages / transmute-did / src / lib / wallet / __tests__ / wallet.spec.js View on Github external
//   eslint-disable-next-line
const { sha3_256 } = require('js-sha3');

const {
  createWallet,
  TransmuteDIDWallet,
  schema,
  sodiumExtensions,
  ethereumExtensions,
} = require('../../../index');

const pack = require('../../../../package.json');

const emptyWalletPath = tmp.fileSync().name;
const fullWalletPath = tmp.fileSync().name;
const cipherTextWalletPath = tmp.fileSync().name;
const recoveredPlaintextWalletPath = tmp.fileSync().name;

const passphrase = 'yolo';

describe('did-wallet', () => {
  describe('createWallet', () => {
    it('has a version', async () => {
      const wallet = await createWallet();
      expect(wallet.data.version).toBe(pack.version);
      expect(schema.validator.isValid(wallet.data, schema.schemas.didWalletPlaintext)).toBe(
        true,
      );
      fs.writeFileSync(emptyWalletPath, stringify(wallet.data, null, 2));
    });
  });
github juttle / juttle / test / adapters / file / write.spec.js View on Github external
'use strict';

var _ = require('underscore');
var expect = require('chai').expect;
var tmp = require('tmp');
var fs = require('fs');
var juttle_test_utils = require('../../runtime/specs/juttle-test-utils');
var check_juttle = juttle_test_utils.check_juttle;
var expect_to_fail = juttle_test_utils.expect_to_fail;
var run_read_file_juttle = require('./utils').run_read_file_juttle;

var tmp_file = tmp.tmpNameSync();

var symmetricalFormats = {
    json: 'json',
    jsonl: 'jsonl',
    csv: 'csv'
};

describe('write file adapter tests', function () {

    afterEach(function() {
        try {
            fs.unlinkSync(tmp_file);
        } catch(err) { /* file not written -- ignore */ }
    });

    it('fails when you do not provide a file to write', function() {
github cliqz-oss / browser-core / tests / runners / ghostery-headless.js View on Github external
async function main() {
  // Package navigation-extension
  const browserCoreArtifact = await createNavigationExtension();
  const baseDirectory = process.cwd();
  const navigationExtensionPath = path.join(baseDirectory, browserCoreArtifact);

  // Move to a temporary directory
  tmp.setGracefulCleanup();
  const tempDir = tmp.dirSync();
  process.chdir(tempDir.name);

  // Package ghostery-extension
  const ghosteryExtensionPath = path.join(
    tempDir.name,
    await createGhosteryExtension(navigationExtensionPath),
  );
  console.log('>>>', ghosteryExtensionPath);

  // Move back to base directory
  process.chdir(baseDirectory);

  // Start tests
  runTests(ghosteryExtensionPath);
}
github oclif / oclif / test / run.js View on Github external
function build(type, features) {
  let options = ''
  if (features === 'everything') options = '--options=yarn,typescript,eslint,mocha'
  if (features === 'typescript') options = '--options=yarn,typescript'
  if (features === 'mocha') options = '--options=yarn,mocha'
  let dir = CI ? tmp.tmpNameSync() : path.join(__dirname, '../tmp')
  dir = path.join(dir, type, features)
  sh.rm('-rf', dir)
  generate(`${type} ${dir} --defaults ${options}`)
  sh.cd(dir)
  // sh.exec('git add .')
  // sh.exec('git commit -nm init')
  // sh.exec('git checkout -B origin/master')
  process.env = npmPath.env({env: process.env})
}
github njpanderson / push / src / ProviderBase.js View on Github external
mkDirRecursive(dir, root, fnDir, dirSeparator = '/') {
		let baseDir, recursiveDir, dirList;

		if (dir === root) {
			// Resolve the promise immediately as the root directory must exist
			return Promise.resolve();
		}

		if (dir.startsWith(root) || dir.includes(tmp.tmpdir)) {
			// Dir starts with the root path, or is part of the temporary file path
			baseDir = utils.trimSeparators(dir.replace(root, ''), dirSeparator);
			recursiveDir = baseDir.split(dirSeparator);
			dirList = [];

			// First, create a directory list for the Promise loop to iterate over
			recursiveDir.reduce((acc, current) => {
				let pathname = (acc === '' ? current : (acc + dirSeparator + current));

				if (pathname !== '') {
					dirList.push(
						utils.addTrailingSeperator(root, dirSeparator) + pathname
					);
				}

				return pathname;
github artilleryio / chaos-lambda / lib / commands / deploy.js View on Github external
function createLambda(role, llamaFile, done) {
  var lambda = new aws.Lambda({apiVersion: '2015-03-31'});

  var archive = archiver.create('zip', {});

  var lambdaPath = path.join(__dirname, '../../lambda/index.js');
  var tmpf = tmp.fileSync();
  var tmpfStream = fs.createWriteStream(tmpf.name);
  archive.pipe(tmpfStream);
  archive.append(fs.readFileSync(lambdaPath), { name: 'index.js' });
  if (llamaFile) {
    debug('Adding real Chaosfile to lambda zip');
    llamaFile.region = process.env.AWS_REGION; // FIXME
    archive.append(new Buffer(JSON.stringify(llamaFile)), { name: 'config.json' });
  } else {
    debug('Adding a stub Chaosfile to lambda zip');
    archive.append(new Buffer(JSON.stringify({enableForASGs: []})), { name: 'config.json' });
  }
  lambdaDependencies.forEach( function (moduleName){
    archive.directory(path.join(__dirname, '..', '..', './node_modules/' + moduleName), 'node_modules/'+ moduleName);
  });

  archive.on('error', function(err) {
github informalsystems / themis-contract / src / shared / contract.ts View on Github external
}
    if (!this.template) {
      throw new Error('Missing template for contract')
    }
    this.computeHash()
    await this.prepareTemplateParams(this.filename)
    if (opts && opts.verify) {
      await this.verify({
        useKeybase: true,
      })
    }

    logger.debug(`Using template params: ${JSON.stringify(this.params, null, 2)}`)
    // render the template to a temporary directory
    const templateExt = this.template.ext ? this.template.ext : DEFAULT_TEMPLATE_EXT
    const tmpContract = tmp.fileSync({ postfix: templateExt })
    try {
      const renderedTemplate = this.template.render(this.params)
      await writeFileAsync(
        tmpContract.name,
        renderedTemplate,
      )
      logger.debug(`Wrote contract to temporary file: ${tmpContract.name}`)
      logger.debug(`Wrote rendered template:\n${renderedTemplate}`)

      logger.info('Generating PDF...')
      if (templateExt === '.tex') {
        await this.compileWithTectonic(tmpContract.name, outputFile)
      } else {
        if (opts && opts.defaults) {
          if (await fileExistsAsync(opts.defaults)) {
            logger.debug(`Compiling using pandoc defaults file ${opts.defaults}`)
github antwarjs / antwar / packages / antwar / src / build / worker.js View on Github external
jsFiles.push(`/${filename}.js`);

      const interactiveIndexEntry = ejs.compile(
        templates.interactiveIndex.file
      )({
        components,
      });
      const entry = ejs.compile(templates.interactive.file)({
        components,
      });

      // Touch output so that other processes get a clue
      touch.sync(interactivePath);

      // Write to a temporary files so we can point webpack to that
      const interactiveEntryTmpFile = tmp.fileSync();
      const entryTmpFile = tmp.fileSync();

      // XXX: convert to async
      _fs.writeFileSync(interactiveEntryTmpFile.name, interactiveIndexEntry);
      _fs.writeFileSync(entryTmpFile.name, entry);

      const interactiveConfig = require(configurationPaths.webpack)(
        "interactive"
      );
      const webpackConfig = merge(interactiveConfig, {
        mode: "production",
        resolve: {
          modules: [cwd, _path.join(cwd, "node_modules")],
          alias: generateAliases(components),
        },
        resolveLoader: {
github SeleniumHQ / selenium / javascript / node / selenium-webdriver / io / index.js View on Github external
return checkedCall(callback => {
    // |tmp.file| checks arguments length to detect options rather than doing a
    // truthy check, so we must only pass options if there are some to pass.
    if (opt_options) {
      tmp.file(opt_options, callback);
    } else {
      tmp.file(callback);
    }
  });
};