Skip to content

Commit

Permalink
test: improve system test (#44)
Browse files Browse the repository at this point in the history
* 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
ofrobots authored Aug 17, 2017
1 parent f447f3c commit 86359e5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 101 deletions.
14 changes: 0 additions & 14 deletions test/fixtures/kitchen/package-lock.json

This file was deleted.

11 changes: 0 additions & 11 deletions test/fixtures/kitchen/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
{
"name": "kitchen",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc -p .",
"fix": "gts fix",
"clean": "gts clean",
"lint": "gts lint"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "^2.4.2",
"google-ts-style": "file:../google-ts-style.tgz"
Expand Down
11 changes: 0 additions & 11 deletions test/fixtures/kitchen/tsconfig.json

This file was deleted.

79 changes: 79 additions & 0 deletions test/test-kitchen.ts
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}`)}`);
}
});
65 changes: 0 additions & 65 deletions test/test.ts

This file was deleted.

0 comments on commit 86359e5

Please # to comment.