-
Notifications
You must be signed in to change notification settings - Fork 879
/
generate_test.ts
63 lines (52 loc) · 1.99 KB
/
generate_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {test} from 'uvu';
// eslint-disable-next-line import/extensions
import * as assert from 'uvu/assert';
import * as fs from 'fs';
import * as path from 'path';
import {Analyzer} from '@lit-labs/analyzer';
import {AbsolutePath} from '@lit-labs/analyzer/lib/paths.js';
import {
installPackage,
buildPackage,
} from '@lit-labs/gen-utils/lib/package-utils.js';
import {writeFileTree} from '@lit-labs/gen-utils/lib/file-utils.js';
import {generateAngularWrapper} from '../../index.js';
import {assertGoldensMatch} from '@lit-internal/tests/utils/assert-goldens.js';
const testProjects = '../test-projects';
const outputFolder = 'gen-output';
test('basic wrapper generation', async () => {
const packageName = '@lit-internal/test-element-a';
const folderName = 'test-element-a';
const inputPackage = path.resolve(testProjects, folderName);
const outputPackage = path.resolve(outputFolder, folderName + '-ng');
if (fs.existsSync(outputPackage)) {
fs.rmSync(outputPackage, {recursive: true});
}
const analyzer = new Analyzer(inputPackage as AbsolutePath);
const analysis = analyzer.analyzePackage();
await writeFileTree(outputFolder, await generateAngularWrapper(analysis));
const wrapperSourceFile = fs.readFileSync(
path.join(outputPackage, 'src', 'element-a.ts')
);
assert.ok(wrapperSourceFile.length > 0);
await assertGoldensMatch(outputPackage, path.join('goldens', folderName), {
formatGlob: '**/*.{ts,js,json}',
});
await installPackage(outputPackage, {
[packageName]: inputPackage,
});
await buildPackage(outputPackage);
// This verifies the package installation and build nominally succeeded. Note
// that runtime tests of this generated package are run as a separate `npm run
// test:output` command via web-test-runner.
const wrapperJsFile = fs.readFileSync(
path.join(outputPackage, 'element-a.js')
);
assert.ok(wrapperJsFile.length > 0);
});
test.run();