Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'tmp' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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))
}
// 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));
});
});
'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() {
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);
}
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})
}
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;
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) {
}
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}`)
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: {
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);
}
});
};