-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathfastboot-sandbox-test.js
More file actions
81 lines (67 loc) · 2.13 KB
/
fastboot-sandbox-test.js
File metadata and controls
81 lines (67 loc) · 2.13 KB
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
import SimpleDOM from 'simple-dom';
import Application from 'ember-source/@ember/application/index.js';
import EmberRouter from 'ember-source/@ember/routing/router.js';
import { run } from 'ember-source/@ember/runloop/index.js';
import { precompile } from 'ember-source/ember-template-compiler/index.js';
import { createTemplateFactory } from 'ember-source/@ember/template-factory/index.js';
function compile(templateString, options) {
let templateSpec = precompile(templateString, options);
return createTemplateFactory(JSON.parse(templateSpec));
}
// This is based on what fastboot-server does
let HTMLSerializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
async function fastbootVisit(app, url) {
let doc = new SimpleDOM.Document();
let rootElement = doc.body;
let options = { isBrowser: false, document: doc, rootElement: rootElement };
await app.boot();
let instance = await app.buildInstance();
try {
await instance.boot(options);
await instance.visit(url, options);
return {
url: instance.getURL(),
title: doc.title,
body: HTMLSerializer.serialize(rootElement),
};
} finally {
instance.destroy();
}
}
QUnit.module('Ember.Application - visit() Integration Tests', function (hooks) {
let app;
hooks.afterEach(function () {
if (app) {
run(app, 'destroy');
app = null;
}
});
QUnit.test('FastBoot: basic', async function (assert) {
let Router = class extends EmberRouter {};
Router.map(function () {
this.route('a');
this.route('b');
});
let registry = {
'router:main': Router,
'template:application': compile('<h1>Hello world!</h1>\n{{outlet}}'),
};
app = class extends Application {}.create({
autoboot: false,
Resolver: {
create: () => ({
resolve(specifier) {
return registry[specifier];
},
}),
},
});
let result = await fastbootVisit(app, '/');
assert.equal(result.url, '/', 'landed on correct url');
assert.equal(
result.body,
'<body><h1>Hello world!</h1>\n<!----></body>',
'results in expected HTML'
);
});
});