-
Notifications
You must be signed in to change notification settings - Fork 879
/
generate_test.ts
69 lines (57 loc) · 2.23 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
64
65
66
67
68
69
/**
* @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,
packPackage,
} from '@lit-labs/gen-utils/lib/package-utils.js';
import {writeFileTree} from '@lit-labs/gen-utils/lib/file-utils.js';
import {generateVueWrapper} 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 project = 'test-element-a';
const inputPackage = path.resolve(testProjects, project);
const outputPackage = path.resolve(outputFolder, project + '-vue');
if (fs.existsSync(outputPackage)) {
fs.rmSync(outputPackage, {recursive: true});
}
const analyzer = new Analyzer(inputPackage as AbsolutePath);
const analysis = analyzer.analyzePackage();
await writeFileTree(outputFolder, await generateVueWrapper(analysis));
const wrapperSourceFile = fs.readFileSync(
path.join(outputPackage, 'src/ElementA.vue')
);
assert.ok(wrapperSourceFile.length > 0);
await assertGoldensMatch(outputPackage, path.join('goldens', project), {
formatGlob: '**/*.{vue,ts,js,json}',
});
await installPackage(outputPackage, {
[`@lit-internal/${project}`]: inputPackage,
'@lit-labs/vue-utils': '../vue-utils',
});
await buildPackage(outputPackage);
// Pack the generated package here, as `test-output` package.json will
// reference the generated tarball here by filename; `test-output:installSelf`
// depends on these tests run by `test:gen`.
await packPackage(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` command in `test-output` using `@web/test-runner`.
const wrapperJsFile = fs.readFileSync(
path.join(outputPackage, 'ElementA.js')
);
assert.ok(wrapperJsFile.length > 0);
});
test.run();