-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use a old-of-tree tmp directory to make sure there is no incidental interaction with parent node_modules * Minimize the test fixtures. * Add system test for `gts init` * Expand test for build. * Simplify test for clean.
- Loading branch information
Showing
5 changed files
with
79 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import test from 'ava'; | ||
import * as chalk from 'chalk'; | ||
import * as cp from 'child_process'; | ||
import * as fs from 'fs'; | ||
import * as ncp from 'ncp'; | ||
import * as path from 'path'; | ||
import * as pify from 'pify'; | ||
import * as rimraf from 'rimraf'; | ||
import * as tmp from 'tmp'; | ||
|
||
const pkg = require('../../package.json'); | ||
|
||
const rimrafp = pify(rimraf); | ||
const mkdirp = pify(fs.mkdir); | ||
const execp = pify(cp.exec); | ||
const renamep = pify(fs.rename); | ||
const ncpp = pify(ncp.ncp); | ||
|
||
const keep = !!process.env.GTS_KEEP_TEMPDIRS; | ||
const stagingDir = tmp.dirSync({keep: keep, unsafeCleanup: true}); | ||
const stagingPath = stagingDir.name; | ||
const execOpts = { | ||
cwd: `${stagingPath}/kitchen` | ||
}; | ||
|
||
/** | ||
* Create a staging directory with temp fixtures used | ||
* to test on a fresh application. | ||
*/ | ||
test.before(async () => { | ||
try { | ||
await execp('npm pack'); | ||
const tarball = `${pkg.name}-${pkg.version}.tgz`; | ||
await renamep(tarball, `${stagingPath}/google-ts-style.tgz`); | ||
await ncpp('test/fixtures', `${stagingPath}/`); | ||
await execp('npm install', execOpts); | ||
} catch (e) { | ||
console.error('Failed to prepare test staging sandbox.'); | ||
console.error(e); | ||
throw e; | ||
} | ||
}); | ||
|
||
test.serial('init', async t => { | ||
await execp('./node_modules/.bin/google-ts-style init -y', execOpts); | ||
fs.accessSync(`${stagingPath}/kitchen/tsconfig.json`); | ||
t.pass(); | ||
}); | ||
|
||
test.serial('build', async t => { | ||
await execp('npm run compile', execOpts); | ||
fs.accessSync(`${stagingPath}/kitchen/build/src/server.js`); | ||
fs.accessSync(`${stagingPath}/kitchen/build/src/server.js.map`); | ||
fs.accessSync(`${stagingPath}/kitchen/build/src/server.d.ts`); | ||
t.pass(); | ||
}); | ||
|
||
/** | ||
* Verify the `gts clean` command actually removes the | ||
* output dir | ||
*/ | ||
test.serial('clean', async t => { | ||
await execp('npm run clean', execOpts); | ||
t.throws(() => { | ||
fs.accessSync(`${stagingPath}/kitchen/build`); | ||
}); | ||
}); | ||
|
||
|
||
/** | ||
* CLEAN UP - remove the staging directory when done. | ||
*/ | ||
test.after.always('cleanup staging', async () => { | ||
if (!keep) { | ||
stagingDir.removeCallback(); | ||
} else { | ||
console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.