Skip to content

Commit 3553205

Browse files
alan-agius4vikerman
authored andcommitted
refactor: scripts array e2e tests to use async/await
1 parent 4f8e349 commit 3553205

File tree

1 file changed

+66
-110
lines changed

1 file changed

+66
-110
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,74 @@
11
// TODO(architect): edit the architect config instead of the cli config.
22

3-
import {
4-
writeMultipleFiles,
5-
expectFileToMatch,
6-
appendToFile,
7-
expectFileMatchToExist,
8-
} from '../../utils/fs';
3+
import { oneLineTrim } from 'common-tags';
4+
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
95
import { ng } from '../../utils/process';
106
import { updateJsonFile } from '../../utils/project';
11-
import { oneLineTrim } from 'common-tags';
12-
import * as fs from 'fs';
13-
import * as path from 'path';
147

15-
// tslint:disable:max-line-length
16-
export default function() {
17-
return (
18-
writeMultipleFiles({
19-
'src/string-script.js': "console.log('string-script'); var number = 1+1;",
20-
'src/zstring-script.js': "console.log('zstring-script');",
21-
'src/fstring-script.js': "console.log('fstring-script');",
22-
'src/ustring-script.js': "console.log('ustring-script');",
23-
'src/bstring-script.js': "console.log('bstring-script');",
24-
'src/astring-script.js': "console.log('astring-script');",
25-
'src/cstring-script.js': "console.log('cstring-script');",
26-
'src/input-script.js': "console.log('input-script');",
27-
'src/lazy-script.js': "console.log('lazy-script');",
28-
'src/pre-rename-script.js': "console.log('pre-rename-script');",
29-
'src/pre-rename-lazy-script.js': "console.log('pre-rename-lazy-script');",
30-
})
31-
.then(() => appendToFile('src/main.ts', "import './string-script.js';"))
32-
.then(() =>
33-
updateJsonFile('angular.json', configJson => {
34-
const appArchitect = configJson.projects['test-project'].architect;
35-
appArchitect.build.options.scripts = [
36-
{ input: 'src/string-script.js' },
37-
{ input: 'src/zstring-script.js' },
38-
{ input: 'src/fstring-script.js' },
39-
{ input: 'src/ustring-script.js' },
40-
{ input: 'src/bstring-script.js' },
41-
{ input: 'src/astring-script.js' },
42-
{ input: 'src/cstring-script.js' },
43-
{ input: 'src/input-script.js' },
44-
{ input: 'src/lazy-script.js', inject: false },
45-
{ input: 'src/pre-rename-script.js', bundleName: 'renamed-script' },
46-
{
47-
input: 'src/pre-rename-lazy-script.js',
48-
bundleName: 'renamed-lazy-script',
49-
inject: false,
50-
},
51-
];
52-
}),
53-
)
54-
.then(() => ng('build', '--extract-css'))
55-
// files were created successfully
56-
.then(() => expectFileToMatch('dist/test-project/scripts.js', 'string-script'))
57-
.then(() => expectFileToMatch('dist/test-project/scripts.js', 'input-script'))
58-
.then(() => expectFileToMatch('dist/test-project/lazy-script.js', 'lazy-script'))
59-
.then(() => expectFileToMatch('dist/test-project/renamed-script.js', 'pre-rename-script'))
60-
.then(() =>
61-
expectFileToMatch('dist/test-project/renamed-lazy-script.js', 'pre-rename-lazy-script'),
62-
)
63-
// index.html lists the right bundles
64-
.then(() =>
65-
expectFileToMatch(
66-
'dist/test-project/index.html',
67-
oneLineTrim`
68-
<script src="runtime-es2015.js" type="module"></script>
69-
<script src="polyfills-es2015.js" type="module"></script>
70-
<script src="runtime-es5.js" nomodule defer></script>
71-
<script src="polyfills-es5.js" nomodule defer></script>
72-
<script src="scripts.js" defer></script>
73-
<script src="renamed-script.js" defer></script>
74-
<script src="vendor-es2015.js" type="module"></script>
75-
<script src="main-es2015.js" type="module"></script>
76-
<script src="vendor-es5.js" nomodule defer></script>
77-
<script src="main-es5.js" nomodule defer></script>
78-
`,
79-
),
80-
)
81-
// Ensure scripts can be separately imported from the app.
82-
.then(() =>
83-
expectFileToMatch('dist/test-project/main-es5.js', "console.log('string-script');"),
84-
)
85-
.then(() =>
86-
expectFileToMatch('dist/test-project/main-es2015.js', "console.log('string-script');"),
87-
)
88-
);
89-
// TODO(architect): disabled until --prod is added.
90-
// Verify uglify, sourcemaps and hashes. Lazy scripts should not get hashes.
91-
// .then(() => ng('build', '--prod', '--source-map'))
92-
// .then(() => expectFileMatchToExist('dist', /scripts\.[0-9a-f]{20}\.js/))
93-
// .then(fileName => expectFileToMatch(`dist/${fileName}`, 'var number=2;'))
94-
// .then(() => expectFileMatchToExist('dist', /scripts\.[0-9a-f]{20}\.js\.map/))
95-
// .then(() => expectFileMatchToExist('dist', /renamed-script\.[0-9a-f]{20}\.js/))
96-
// .then(() => expectFileMatchToExist('dist', /renamed-script\.[0-9a-f]{20}\.js.map/))
97-
// .then(() => expectFileToMatch('dist/test-project/lazy-script.js', 'lazy-script'))
98-
// .then(() => expectFileToMatch('dist/test-project/enamed-lazy-script.js', 'pre-rename-lazy-script'))
8+
export default async function () {
9+
await writeMultipleFiles({
10+
'src/string-script.js': "console.log('string-script'); var number = 1+1;",
11+
'src/zstring-script.js': "console.log('zstring-script');",
12+
'src/fstring-script.js': "console.log('fstring-script');",
13+
'src/ustring-script.js': "console.log('ustring-script');",
14+
'src/bstring-script.js': "console.log('bstring-script');",
15+
'src/astring-script.js': "console.log('astring-script');",
16+
'src/cstring-script.js': "console.log('cstring-script');",
17+
'src/input-script.js': "console.log('input-script');",
18+
'src/lazy-script.js': "console.log('lazy-script');",
19+
'src/pre-rename-script.js': "console.log('pre-rename-script');",
20+
'src/pre-rename-lazy-script.js': "console.log('pre-rename-lazy-script');",
21+
});
22+
23+
await appendToFile('src/main.ts', "import './string-script.js';");
9924

100-
// // Expect order to be preserved.
101-
// .then(() => {
102-
// const [fileName] = fs.readdirSync('dist')
103-
// .filter(name => name.match(/^scripts\..*\.js$/));
25+
await updateJsonFile('angular.json', configJson => {
26+
const appArchitect = configJson.projects['test-project'].architect;
27+
appArchitect.build.options.scripts = [
28+
{ input: 'src/string-script.js' },
29+
{ input: 'src/zstring-script.js' },
30+
{ input: 'src/fstring-script.js' },
31+
{ input: 'src/ustring-script.js' },
32+
{ input: 'src/bstring-script.js' },
33+
{ input: 'src/astring-script.js' },
34+
{ input: 'src/cstring-script.js' },
35+
{ input: 'src/input-script.js' },
36+
{ input: 'src/lazy-script.js', inject: false },
37+
{ input: 'src/pre-rename-script.js', bundleName: 'renamed-script' },
38+
{
39+
input: 'src/pre-rename-lazy-script.js',
40+
bundleName: 'renamed-lazy-script',
41+
inject: false,
42+
},
43+
];
44+
});
10445

105-
// const content = fs.readFileSync(path.join('dist', fileName), 'utf-8');
106-
// const re = new RegExp(/['"]string-script['"].*/.source
107-
// + /['"]zstring-script['"].*/.source
108-
// + /['"]fstring-script['"].*/.source
109-
// + /['"]ustring-script['"].*/.source
110-
// + /['"]bstring-script['"].*/.source
111-
// + /['"]astring-script['"].*/.source
112-
// + /['"]cstring-script['"].*/.source
113-
// + /['"]input-script['"]/.source);
114-
// if (!content.match(re)) {
115-
// throw new Error('Scripts are not included in order.');
116-
// }
117-
// });
46+
await ng('build', '--extract-css');
47+
48+
// files were created successfully
49+
await expectFileToMatch('dist/test-project/scripts.js', 'string-script');
50+
await expectFileToMatch('dist/test-project/scripts.js', 'input-script');
51+
await expectFileToMatch('dist/test-project/lazy-script.js', 'lazy-script');
52+
await expectFileToMatch('dist/test-project/renamed-script.js', 'pre-rename-script');
53+
await expectFileToMatch('dist/test-project/renamed-lazy-script.js', 'pre-rename-lazy-script');
54+
55+
// index.html lists the right bundles
56+
await expectFileToMatch(
57+
'dist/test-project/index.html',
58+
oneLineTrim`
59+
<script src="runtime-es2015.js" type="module"></script>
60+
<script src="polyfills-es2015.js" type="module"></script>
61+
<script src="runtime-es5.js" nomodule defer></script>
62+
<script src="polyfills-es5.js" nomodule defer></script>
63+
<script src="scripts.js" defer></script>
64+
<script src="renamed-script.js" defer></script>
65+
<script src="vendor-es2015.js" type="module"></script>
66+
<script src="main-es2015.js" type="module"></script>
67+
<script src="vendor-es5.js" nomodule defer></script>
68+
<script src="main-es5.js" nomodule defer></script>
69+
`,
70+
);
71+
// Ensure scripts can be separately imported from the app.
72+
await expectFileToMatch('dist/test-project/main-es5.js', "console.log('string-script');");
73+
await expectFileToMatch('dist/test-project/main-es2015.js', "console.log('string-script');");
11874
}

0 commit comments

Comments
 (0)