-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.test.ts
124 lines (111 loc) · 3.71 KB
/
web.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import {
checkFilesExist,
ensureProject,
readFile,
runCLI,
runCLIAsync,
uniq,
forEachCli,
supportUi,
updateFile
} from './utils';
import { stripIndents } from '@angular-devkit/core/src/utils/literals';
forEachCli(currentCLIName => {
describe('Web Components Applications', () => {
it('should be able to generate a web app', async () => {
ensureProject();
const appName = uniq('app');
const linter = currentCLIName === 'angular' ? 'tslint' : 'eslint';
runCLI(
`generate @nrwl/web:app ${appName} --no-interactive --linter=${linter}`
);
const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
runCLI(`build ${appName}`);
checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/runtime.js`,
`dist/apps/${appName}/polyfills.js`,
`dist/apps/${appName}/main.js`,
`dist/apps/${appName}/styles.js`
);
expect(readFile(`dist/apps/${appName}/main.js`)).toContain(
'class AppElement'
);
runCLI(`build ${appName} --prod --output-hashing none`);
checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/runtime.js`,
`dist/apps/${appName}/polyfills.esm.js`,
`dist/apps/${appName}/main.esm.js`,
`dist/apps/${appName}/polyfills.es5.js`,
`dist/apps/${appName}/main.es5.js`,
`dist/apps/${appName}/styles.css`
);
expect(readFile(`dist/apps/${appName}/index.html`)).toContain(
`<link rel="stylesheet" href="styles.css">`
);
const testResults = await runCLIAsync(`test ${appName}`);
expect(testResults.stderr).toContain('Test Suites: 1 passed, 1 total');
const lintE2eResults = runCLI(`lint ${appName}-e2e`);
expect(lintE2eResults).toContain('All files pass linting.');
if (supportUi()) {
const e2eResults = runCLI(`e2e ${appName}-e2e`);
expect(e2eResults).toContain('All specs passed!');
}
}, 120000);
it('should support same syntax as TypeScript', () => {
ensureProject();
const appName = uniq('app');
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`);
const mainPath = `apps/${appName}/src/app/app.element.ts`;
const content = readFile(mainPath);
updateFile(
mainPath,
content
// Testing decorators
.replace(
`export class AppElement extends HTMLElement`,
stripIndents`
function myDecorator(ctor) {
ctor.title = '${appName}';
}
@myDecorator
export class AppElement extends HTMLElement`
)
.replace('${title}', '${(AppElement as any).title}') +
// Testing const enums
stripIndents`
export const enum MyEnum {
a,
b,
b
};
`
);
if (supportUi()) {
const e2eResults = runCLI(`e2e ${appName}-e2e`);
expect(e2eResults).toContain('All specs passed!');
}
});
it('should support CSS modules', () => {
ensureProject();
const appName = uniq('app');
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`);
updateFile(
`apps/${appName}/src/app/app.module.css`,
'.foo { color: red; }'
);
const mainPath = `apps/${appName}/src/app/app.element.ts`;
const content = readFile(mainPath);
updateFile(
mainPath,
`import styles from './app.module.css';\n${content}`
);
if (supportUi()) {
const e2eResults = runCLI(`e2e ${appName}-e2e`);
expect(e2eResults).toContain('All specs passed!');
}
});
});
});