test.serial('Installing a non-shrinkpacked project produces expected output', async t => { await testUtil.createTestApp(nonShrinkpackApp, testPackageJson); await testUtil.npmInstall(nonShrinkpackApp); const controlModuleTree = await testUtil.getAllDirFiles(path.join(controlApp, 'node_modules')); const nonShrinkpackModuleTree = await testUtil.getAllDirFiles(path.join(nonShrinkpackApp, 'node_modules')); t.deepEqual(nonShrinkpackModuleTree, controlModuleTree); await testUtil.rmDirs(nonShrinkpackApp); });
test.serial('Reinstalling from shrinkpack produces expected output', async t => { await testUtil.rmDirs(path.join(shrinkpackApp, 'node_modules')); await testUtil.npmInstall(shrinkpackApp); const controlModuleTree = await testUtil.getAllDirFiles(path.join(controlApp, 'node_modules')); const shrinkpackModuleTree = await testUtil.getAllDirFiles(path.join(shrinkpackApp, 'node_modules')); t.deepEqual(shrinkpackModuleTree, controlModuleTree); });
test.serial('Running shrinkpack updates the shrinkwrap file', async t => { await testUtil.shrinkwrap(shrinkpackApp); const beforeShrinkpack = await testUtil.getShrinkwrapFile(shrinkpackApp); await testUtil.shrinkpack(shrinkpackApp); const afterShrinkpack = await testUtil.getShrinkwrapFile(shrinkpackApp); t.not(beforeShrinkpack, afterShrinkpack); });
test.serial('All deps in shrinkpacked shrinkwrap have resolved prop and point to local file', async t => { const afterShrinkpack = await testUtil.getShrinkwrapFile(shrinkpackApp); const {dependencies} = JSON.parse(afterShrinkpack); const assertAllResolves = deps => { Object.keys(deps).forEach(depName => { const dep = deps[depName]; t.true(dep.resolved.indexOf('./node_shrinkwrap/') > -1); if (dep.dependencies) { assertAllResolves(dep.dependencies); } }); }; assertAllResolves(dependencies); });
test.serial('Correct npm version was installed', async t => { const actualNpmVersion = await testUtil.getNpmVersion(); t.is(actualNpmVersion, process.env.NPM_VERSION); });
test.serial('Running shrinkpack does not affect installation', async t => { const controlModuleTree = await testUtil.getAllDirFiles(path.join(controlApp, 'node_modules')); const shrinkpackModuleTree = await testUtil.getAllDirFiles(path.join(shrinkpackApp, 'node_modules')); t.deepEqual(shrinkpackModuleTree, controlModuleTree); });
test.serial('display incomplete task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { let { trackName, fileExtension } = learningTracksInfo[index]; let userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig, null, 2)); const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey6']); t.snapshot(stdout); fs.unlinkSync(configFilePath); fs.unlinkSync(path.join(process.cwd(), `task6.${fileExtension}`)); } });
test.serial('should run test with overrides', async t => { const cmd = 'npm'; const results = await tools.spawnAsyncWithIO( binPath, ['test', 'run', `--cmd=${cmd}`, '--', 'run', 'test', '--foo="bar"'], samplePath ); t.regex(results.output, new RegExp(`run: Executing tests in: ${samplePath}`)); t.regex(results.output, new RegExp(`run: Running: npm run test --foo=bar`)); t.regex(results.output, new RegExp(`run: Success!`)); });
// 1. Tests for the GCStoPubsub method test.serial(`GCStoPubsub fails without a bucket`, async (t) => { const error = new Error(`Bucket not provided. Make sure you have a "bucket" property in your request`); const event = { data: { data: Buffer.from(JSON.stringify({ name, contentType })).toString(`base64`) } }; const err = await t.throws(getSample(null).program.GCStoPubsub(event)); t.deepEqual(err, error); });
test.serial('directory()', async t => { t.true(typeof temp.directory() === 'string'); t.true(temp.directory() !== temp.directory()); t.true(await pathExists(temp.directory())); });
test.serial('Exmaple module - no AST', async t => { const mutode = new Mutode({ paths: 'src/no-ast.js', concurrency: 1 }) await t.throws(mutode.run()) })
test.serial('display completed task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { let { trackName, fileExtension } = learningTracksInfo[index]; let userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig, null, 2)); const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey2']); t.snapshot(stdout); fs.unlinkSync(configFilePath); } });
test.serial(`visionAPI fails without a contentType`, async (t) => { const error = new Error(`ContentType not provided. Make sure you have a "contentType" property in your request`); const event = { data: { data: Buffer.from(JSON.stringify({gcsUrl:jpegGCSUrl,gcsBucket: jpegBucket, gcsFile: jpegName} )).toString(`base64`) } }; const err = await t.throws(getSample(null).program.visionAPI(event)); t.deepEqual(err, error); });
test.serial(`GCStoPubsub fails without a filename`, async (t) => { const error = new Error(`Filename not provided. Make sure you have a "name" property in your request`); const event = { data: { data: Buffer.from(JSON.stringify({ contentType, bucket })).toString(`base64`) } }; const err = await t.throws(getSample(null).program.GCStoPubsub(event)); t.deepEqual(err, error); });
test.serial(`GCStoPubsub fails without a contentType`, async (t) => { const error = new Error(`ContentType not provided. Make sure you have a "contentType" property in your request`); const event = { data: { data: Buffer.from(JSON.stringify({ name, bucket })).toString(`base64`) } }; const err = await t.throws(getSample(null).program.GCStoPubsub(event)); t.deepEqual(err, error); });