-
Notifications
You must be signed in to change notification settings - Fork 22
/
extension-tests.ts
54 lines (45 loc) · 1.59 KB
/
extension-tests.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
50
51
52
53
54
import 'jasmine';
import fs from 'fs';
import path from 'path';
import {TEST_ONLY as TSExtension} from '../src/extension/typescript';
/**
* Eleventy extension tests.
*/
describe('Eleventy extension', () => {
/**
* Tests for the TS -> JS extension.
*/
describe('TS -> JS', () => {
const {tsToJs} = TSExtension;
const DATA_DIR =
path.resolve(__dirname, './extension-tests-data/typescript');
function unformat(input: string) {
return input.replace(/[\n|\s]/g, '');
}
const testFiles = fs.readdirSync(DATA_DIR);
for (const file of testFiles) {
if (!path.basename(file).endsWith('-ts')) continue;
const input = fs.readFileSync(path.join(DATA_DIR, file), 'utf-8');
it(`${file} to ES2020 passes`, () => {
const convertedOutput = tsToJs(input, false);
if (!convertedOutput) {
fail(`${file} JS conversion failed`);
} else {
const fileName = path.basename(file).replace('-ts', '-js');
const output = fs.readFileSync(path.join(DATA_DIR, fileName), 'utf8');
expect(unformat(convertedOutput)).toBe(unformat(output));
}
});
it(`${file} to ES5 passes`, () => {
const convertedOutput = tsToJs(input, true);
if (!convertedOutput) {
fail(`${file} legacy JS conversion failed`);
} else {
const fileName = path.basename(file).replace('-ts', '-legacyjs');
const output = fs.readFileSync(path.join(DATA_DIR, fileName), 'utf8');
expect(unformat(convertedOutput)).toBe(unformat(output));
}
});
}
});
});