/
integration-test.js
49 lines (39 loc) · 1.43 KB
/
integration-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const os = require('os');
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
const { describe, it } = require('mocha');
function exec(command, options = {}) {
const output = childProcess.execSync(command, {
encoding: 'utf-8',
...options,
});
return output && output.trimEnd();
}
describe('Integration Tests', () => {
const tmpDir = path.join(os.tmpdir(), 'graphql-js-integrationTmp');
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir);
const distDir = path.resolve('./npmDist');
const archiveName = exec(`npm --quiet pack ${distDir}`, { cwd: tmpDir });
fs.renameSync(
path.join(tmpDir, archiveName),
path.join(tmpDir, 'graphql.tgz'),
);
function testOnNodeProject(projectName) {
const projectPath = path.join(__dirname, projectName);
const packageJSONPath = path.join(projectPath, 'package.json');
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'));
it(packageJSON.description, () => {
exec(`cp -R ${projectPath} ${tmpDir}`);
const cwd = path.join(tmpDir, projectName);
// TODO: figure out a way to run it with --ignore-scripts
exec('npm --quiet install', { cwd, stdio: 'inherit' });
exec('npm --quiet test', { cwd, stdio: 'inherit' });
}).timeout(60000);
}
testOnNodeProject('ts');
testOnNodeProject('node');
testOnNodeProject('webpack');
});