forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration-test.ts
49 lines (40 loc) · 1.49 KB
/
integration-test.ts
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
import * as childProcess from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { describe, it } from 'mocha';
function exec(command: string, options = {}) {
const output = childProcess.execSync(command, {
encoding: 'utf-8',
...options,
});
return 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: string) {
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, () => {
fs.cpSync(projectPath, path.join(tmpDir, projectName), {
recursive: true,
});
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(120000);
}
testOnNodeProject('ts');
testOnNodeProject('node');
testOnNodeProject('webpack');
});