-
Notifications
You must be signed in to change notification settings - Fork 137
/
compat-dummy-app-test.ts
102 lines (90 loc) · 3.63 KB
/
compat-dummy-app-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
import type { ExpectFile } from '@embroider/test-support/file-assertions/qunit';
import { expectRewrittenFilesAt } from '@embroider/test-support/file-assertions/qunit';
import { Rebuilder } from '@embroider/test-support';
import type { PreparedApp } from 'scenario-tester';
import { throwOnWarnings } from '@embroider/core';
import merge from 'lodash/merge';
import { readFileSync, writeFileSync } from 'fs';
import { join, resolve } from 'path';
import QUnit from 'qunit';
const { module: Qmodule, test } = QUnit;
import fetch from 'node-fetch';
import { dummyAppScenarios } from './scenarios';
import CommandWatcher from './helpers/command-watcher';
dummyAppScenarios
.map('compat-dummy-app-tests', project => {
merge(project.files, {
addon: {
components: {
'example.hbs': `hello`,
},
},
public: {
'from-addon.txt': 'a public asset provided by the classic addon',
},
tests: {
dummy: {
public: {
'robots.txt': 'go away bots',
},
},
},
});
project.linkDevDependency('@embroider/core', { baseDir: __dirname });
project.linkDevDependency('@embroider/compat', { baseDir: __dirname });
project.linkDevDependency('@embroider/webpack', { baseDir: __dirname });
})
.forEachScenario(scenario => {
Qmodule(`${scenario.name} - rebuild`, function (hooks) {
throwOnWarnings(hooks);
let app: PreparedApp;
let builder: Rebuilder;
let expectFile: ExpectFile;
hooks.before(async () => {
app = await scenario.prepare();
builder = await Rebuilder.create(app.dir, { EMBROIDER_PREBUILD: 'true' });
});
hooks.after(async () => {
await builder?.shutdown();
});
hooks.beforeEach(assert => {
expectFile = expectRewrittenFilesAt(resolve(app.dir, 'tests/dummy'), {
qunit: assert,
});
});
test('rebuilds addon code', async function () {
expectFile('../../components/example.hbs').matches(/hello/);
writeFileSync(join(app.dir, 'addon/components/example.hbs'), 'goodbye');
await builder.build({ changedDirs: [app.dir] });
expectFile('../../components/example.hbs').matches(/goodbye/);
});
});
Qmodule(`${scenario.name} - public assets`, function (hooks) {
throwOnWarnings(hooks);
let app: PreparedApp;
hooks.before(async () => {
app = await scenario.prepare();
});
test('production build contains public assets from both addon and dummy app after a build', async function (assert) {
await app.execute(`pnpm vite build`);
let content = readFileSync(`${app.dir}/dist/robots.txt`).toString();
assert.strictEqual(content, 'go away bots');
content = readFileSync(`${app.dir}/dist/addon-template/from-addon.txt`).toString();
assert.strictEqual(content, 'a public asset provided by the classic addon');
});
test('dev mode serves public assets from both addon and dummy app', async function (assert) {
const server = CommandWatcher.launch('vite', ['--clearScreen', 'false'], { cwd: app.dir });
try {
const [, url] = await server.waitFor(/Local:\s+(https?:\/\/.*)\//g);
let response = await fetch(`${url}/robots.txt`);
let text = await response.text();
assert.strictEqual(text, 'go away bots');
response = await fetch(`${url}/addon-template/from-addon.txt`);
text = await response.text();
assert.strictEqual(text, 'a public asset provided by the classic addon');
} finally {
await server.shutdown();
}
});
});
});