Skip to content

Commit bc7c01c

Browse files
committed
Integration test the fully built & bundled package
1 parent 3569a51 commit bc7c01c

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ addons:
2323

2424
jobs:
2525
include:
26-
- stage: Release prebuilt binaries
26+
- stage: Build and release binaries
2727
node_js: '10.15.3'
28-
echo: 'Deploying prebuilt binaries...'
29-
script: npm run build
28+
echo: 'Building binaries...'
29+
script:
30+
- |
31+
npm run build
32+
npm run test:release
3033
before_deploy:
3134
- |
3235
echo "Travis tag was $TRAVIS_TAG"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'tarball-extract';

package-lock.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"build:src": "rm -rf lib && tsc -b",
2020
"build:release": "oclif-dev manifest && webpack && ts-node ./pack.ts",
2121
"prepack": "npm run build:src && oclif-dev manifest",
22-
"test": "TS_NODE_FILES=true mocha -r ts-node/register 'test/**/*.spec.ts'"
22+
"test": "TS_NODE_FILES=true mocha -r ts-node/register 'test/**/*.spec.ts'",
23+
"test:release": "TEST_BUILT_TARBALL=1 npm run test"
2324
},
2425
"repository": "httptoolkit/httptoolkit-server",
2526
"homepage": "https://github.com/httptoolkit/httptoolkit-server",
@@ -79,6 +80,7 @@
7980
"reqwest": "^2.0.5",
8081
"stripe": "^7.4.0",
8182
"superagent": "^5.1.0",
83+
"tarball-extract": "0.0.6",
8284
"tmp": "0.0.33",
8385
"ts-loader": "^6.0.0",
8486
"ts-node": "^7.0.1",

test/integration-test.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
1+
import { promisify } from 'util';
12
import { spawn, ChildProcess } from 'child_process';
23
import * as path from 'path';
34
import { getRemote } from 'mockttp';
45
import * as request from 'request-promise-native';
6+
import * as tmp from 'tmp';
7+
import { extractTarball as extractTarballCb } from 'tarball-extract';
8+
const extractTarball = promisify(extractTarballCb) as (source: string, dest: string) => Promise<void>;
59

610
import * as getGraphQL from 'graphql.js';
711

812
import { delay } from '../src/util';
913
import { expect } from 'chai';
1014

15+
async function setupServerPath() {
16+
if (!process.env.TEST_BUILT_TARBALL) {
17+
// By default, test the current folder code
18+
return path.join(__dirname, '..', 'bin', 'run');
19+
}
20+
21+
// If TEST_BUILT_TARBALL is set, test the latest build ready-to-go tarball:
22+
const tmpDir = tmp.dirSync({ unsafeCleanup: true }).name;
23+
const version = require(path.join('..', 'package.json')).version;
24+
const tarballPath = path.join(
25+
__dirname,
26+
'..',
27+
'build',
28+
'dist',
29+
`v${version}`,
30+
`httptoolkit-server-v${version}.tar.gz`
31+
);
32+
33+
console.log('Extracting built tarball to', tmpDir);
34+
await extractTarball(tarballPath, tmpDir);
35+
36+
// Pretend this is being called by the real startup script,
37+
// so it acts like a proper prod build.
38+
process.env.HTTPTOOLKIT_SERVER_BINPATH = 'PROD-TEST';
39+
return path.join(tmpDir, 'httptoolkit-server', 'bin', 'run');
40+
}
41+
1142
describe('Integration test', function () {
1243
// Timeout needs to be long, as first test runs (e.g. in CI) generate
1344
// fresh certificates, which can take a little while.
@@ -18,7 +49,9 @@ describe('Integration test', function () {
1849
let stderr = '';
1950

2051
beforeEach(async () => {
21-
serverProcess = spawn(path.join(__dirname, '..', 'bin', 'run'), ['start'], {
52+
const serverRunPath = await setupServerPath();
53+
54+
serverProcess = spawn(serverRunPath, ['start'], {
2255
stdio: 'pipe'
2356
});
2457
stdout = "";

0 commit comments

Comments
 (0)