-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.js
42 lines (36 loc) · 1.48 KB
/
index.spec.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
const assert = require('assert');
const execSync = require('child_process').execSync;
const fs = require('fs');
describe('tsconfig-generator', () =>
{
const generatedFilePath = 'test/tsconfig.json';
before(() =>
{
// NOTE: Using relative paths to make sure that the tests work on any CWD.
process.env['TEST_NODE_PATH'] = '../../test/node/path';
process.env['TEST_GIT_ROOT'] = '../../test/git/root';
process.env['PROJECT_NAME'] = 'foo';
});
after(() =>
{
fs.unlinkSync(generatedFilePath);
});
it('can generate the tsconfig.json with environment variables', () =>
{
let inputFilePath = 'test/tsconfig.sample1.json';
let expectedFilePath = 'test/tsconfig.expected1.json';
execSync(`./index.js -i ${inputFilePath} -o ${generatedFilePath}`);
assert(checkFileEquality(expectedFilePath, generatedFilePath));
});
it('should throw an error if the configuration template includes an invalid environment variable', () =>
{
let inputFilePath = 'test/tsconfig.sample2.json';
assert.throws(() => { execSync(`./index.js -i ${inputFilePath} -o ${generatedFilePath}`, { stdio: 'ignore' }); });
});
function checkFileEquality(expectedFilePath, generatedFilePath)
{
let expectedFileBuffer = fs.readFileSync(expectedFilePath);
let generatedFileBuffer = fs.readFileSync(generatedFilePath);
return expectedFileBuffer.equals(generatedFileBuffer);
}
});