Skip to content

Commit 86359e5

Browse files
authored
test: improve system test (#44)
* 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.
1 parent f447f3c commit 86359e5

File tree

5 files changed

+79
-101
lines changed

5 files changed

+79
-101
lines changed

test/fixtures/kitchen/package-lock.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/fixtures/kitchen/package.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
{
22
"name": "kitchen",
33
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
6-
"scripts": {
7-
"build": "tsc -p .",
8-
"fix": "gts fix",
9-
"clean": "gts clean",
10-
"lint": "gts lint"
11-
},
12-
"keywords": [],
13-
"author": "",
14-
"license": "ISC",
154
"devDependencies": {
165
"typescript": "^2.4.2",
176
"google-ts-style": "file:../google-ts-style.tgz"

test/fixtures/kitchen/tsconfig.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/test-kitchen.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import test from 'ava';
2+
import * as chalk from 'chalk';
3+
import * as cp from 'child_process';
4+
import * as fs from 'fs';
5+
import * as ncp from 'ncp';
6+
import * as path from 'path';
7+
import * as pify from 'pify';
8+
import * as rimraf from 'rimraf';
9+
import * as tmp from 'tmp';
10+
11+
const pkg = require('../../package.json');
12+
13+
const rimrafp = pify(rimraf);
14+
const mkdirp = pify(fs.mkdir);
15+
const execp = pify(cp.exec);
16+
const renamep = pify(fs.rename);
17+
const ncpp = pify(ncp.ncp);
18+
19+
const keep = !!process.env.GTS_KEEP_TEMPDIRS;
20+
const stagingDir = tmp.dirSync({keep: keep, unsafeCleanup: true});
21+
const stagingPath = stagingDir.name;
22+
const execOpts = {
23+
cwd: `${stagingPath}/kitchen`
24+
};
25+
26+
/**
27+
* Create a staging directory with temp fixtures used
28+
* to test on a fresh application.
29+
*/
30+
test.before(async () => {
31+
try {
32+
await execp('npm pack');
33+
const tarball = `${pkg.name}-${pkg.version}.tgz`;
34+
await renamep(tarball, `${stagingPath}/google-ts-style.tgz`);
35+
await ncpp('test/fixtures', `${stagingPath}/`);
36+
await execp('npm install', execOpts);
37+
} catch (e) {
38+
console.error('Failed to prepare test staging sandbox.');
39+
console.error(e);
40+
throw e;
41+
}
42+
});
43+
44+
test.serial('init', async t => {
45+
await execp('./node_modules/.bin/google-ts-style init -y', execOpts);
46+
fs.accessSync(`${stagingPath}/kitchen/tsconfig.json`);
47+
t.pass();
48+
});
49+
50+
test.serial('build', async t => {
51+
await execp('npm run compile', execOpts);
52+
fs.accessSync(`${stagingPath}/kitchen/build/src/server.js`);
53+
fs.accessSync(`${stagingPath}/kitchen/build/src/server.js.map`);
54+
fs.accessSync(`${stagingPath}/kitchen/build/src/server.d.ts`);
55+
t.pass();
56+
});
57+
58+
/**
59+
* Verify the `gts clean` command actually removes the
60+
* output dir
61+
*/
62+
test.serial('clean', async t => {
63+
await execp('npm run clean', execOpts);
64+
t.throws(() => {
65+
fs.accessSync(`${stagingPath}/kitchen/build`);
66+
});
67+
});
68+
69+
70+
/**
71+
* CLEAN UP - remove the staging directory when done.
72+
*/
73+
test.after.always('cleanup staging', async () => {
74+
if (!keep) {
75+
stagingDir.removeCallback();
76+
} else {
77+
console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`);
78+
}
79+
});

test/test.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)