Skip to content

Commit 9452eaf

Browse files
committed
Add CI test verifying Mustache works in browser as AMD w/RequireJS
This is a precursor to introducing a build step that will change what we expose from this package. Better off writing some tests to verify existing projects with different module systems continue to work as expected.
1 parent 05e3ba0 commit 9452eaf

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src='https://unpkg.com/[email protected]/require.js'></script>
5+
<script>
6+
require.config({
7+
paths: {
8+
mustache: '../../../mustache'
9+
}
10+
});
11+
12+
// Placed here rather in the -test.js file because it makes debugging in
13+
// a local browser simpler because this .html file can be opened by double
14+
// clicking the file and inspecting any errors/unexpected results
15+
requirejs(['mustache'], Mustache => {
16+
document.body.textContent = Mustache.render(
17+
'{{title}} spends {{calc}}',
18+
{
19+
title: 'Joe',
20+
calc: () => 2 + 4
21+
});
22+
});
23+
</script>
24+
</head>
25+
<body>Text content to be overwritten<body>
26+
</html>

test/module-systems/browser-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,16 @@ describe('Browser usage', () => {
3434

3535
chai.assert.equal(value.trim(), 'Joe spends 6');
3636
});
37+
38+
it('is exposed as AMD and consumable via RequireJS', async function () {
39+
this.timeout(10 * 1000);
40+
41+
await page.goto(`file://${path.join(__dirname, '_fixtures/amd.html')}`, { waitUntil: 'networkidle0' });
42+
43+
const bodyElement = await page.$('body');
44+
const textContentProperty = await bodyElement.getProperty('textContent');
45+
const value = await textContentProperty.jsonValue();
46+
47+
chai.assert.equal(value, 'Joe spends 6');
48+
});
3749
});

0 commit comments

Comments
 (0)