Skip to content

Commit 978f2d8

Browse files
committed
Setup addon tests
1 parent c91689f commit 978f2d8

File tree

25 files changed

+409
-9
lines changed

25 files changed

+409
-9
lines changed

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ init:
77
# Test against these versions of Node.js.
88
environment:
99
matrix:
10-
- nodejs_version: "4.8.4"
1110
- nodejs_version: "6.11.4"
1211

1312
# Install scripts. (runs after repo cloning)

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
"devDependencies": {
3737
"broccoli-asset-rev": "^2.4.5",
3838
"broccoli-test-helper": "^1.2.0",
39-
"chai": "^4.1.2",
39+
"chai": "^4.2.0",
40+
"chai-fs": "^2.0.0",
4041
"co": "^4.6.0",
4142
"ember-cli": "~3.5.1",
43+
"ember-cli-addon-tests": "^0.11.0",
4244
"ember-cli-dependency-checker": "^3.0.0",
4345
"ember-cli-fastboot": "^2.0.0",
4446
"ember-cli-htmlbars": "^3.0.1",
@@ -58,6 +60,8 @@
5860
"eslint": "^5.9.0",
5961
"eslint-plugin-ember": "^6.0.1",
6062
"eslint-plugin-node": "^8.0.0",
63+
"fs-extra": "^7.0.1",
64+
"glob": "^7.1.3",
6165
"lerna-changelog": "^0.8.2",
6266
"loader.js": "^4.2.3",
6367
"mocha": "^5.2.0"
@@ -69,6 +73,7 @@
6973
"configPath": "tests/dummy/config",
7074
"fastbootDependencies": [
7175
"node-fetch",
76+
"abortcontroller-polyfill",
7277
"abortcontroller-polyfill/dist/cjs-ponyfill"
7378
]
7479
}

test/fastboot-build-test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
const chai = require('chai');
3+
const expect = chai.expect;
4+
chai.use(require('chai-fs'));
5+
6+
const glob = require('glob');
7+
8+
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
9+
10+
describe('it builds with ember-cli-fastboot', function() {
11+
this.timeout(300000);
12+
13+
let app;
14+
15+
before(function() {
16+
app = new AddonTestApp();
17+
18+
return app
19+
.create('dummy', { skipNpm: true })
20+
.then(app =>
21+
app.editPackageJSON(pkg => {
22+
pkg.devDependencies['ember-cli-fastboot'] = '*';
23+
})
24+
)
25+
.then(() => app.run('npm', 'install'));
26+
});
27+
28+
it('builds into dist/ember-fetch/fetch-fastboot.js', function() {
29+
return app.runEmberCommand('build').then(function() {
30+
expect(app.filePath('dist/index.html')).to.be.a.file();
31+
expect(app.filePath('dist/ember-fetch/fetch-fastboot.js')).to.be.a.file();
32+
expect(app.filePath('dist/assets/dummy-fastboot.js')).to.be.a.file();
33+
});
34+
});
35+
36+
it('produces a production build with --environment=production', function() {
37+
return app
38+
.runEmberCommand('build', '--environment=production')
39+
.then(function() {
40+
expect(app.filePath('dist/index.html')).to.be.a.file();
41+
expect(find('dist/ember-fetch/fetch-fastboot-*.js')).to.be.a.file();
42+
expect(find('dist/ember-fetch/fetch-fastboot-*.js')).to.match(
43+
/fetch-fastboot-\w{32}/,
44+
'file name should contain MD5 fingerprint'
45+
);
46+
47+
expect(find('dist/assets/dummy-fastboot-*.js')).to.be.a.file();
48+
expect(find('dist/assets/dummy-fastboot-*.js')).to.match(
49+
/dummy-fastboot-\w{32}/,
50+
'file name should contain MD5 fingerprint'
51+
);
52+
});
53+
});
54+
55+
function find(globPath) {
56+
globPath = app.filePath(globPath);
57+
let files = glob.sync(globPath);
58+
59+
expect(files.length).to.equal(1, globPath);
60+
61+
return files[0];
62+
}
63+
});

test/fastboot-test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
const fs = require('fs-extra');
3+
const request = require('request');
4+
const get = require('rsvp').denodeify(request);
5+
const chai = require('chai');
6+
const expect = chai.expect;
7+
chai.use(require('chai-fs'));
8+
9+
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
10+
11+
describe('renders in fastboot build', function() {
12+
this.timeout(300000);
13+
14+
let app;
15+
16+
before(function() {
17+
app = new AddonTestApp();
18+
19+
return app
20+
.create('dummy', { skipNpm: true })
21+
.then(app =>
22+
app.editPackageJSON(pkg => {
23+
pkg.devDependencies['ember-cli-fastboot'] = '*';
24+
})
25+
)
26+
.then(() => app.run('npm', 'install'))
27+
.then(() =>
28+
app.startServer({
29+
command: 'serve'
30+
})
31+
);
32+
});
33+
34+
after(function() {
35+
return app.stopServer();
36+
});
37+
38+
it('fetches in fastboot mode', function() {
39+
let pkg = fs.readJsonSync(app.filePath('/dist/package.json'));
40+
console.log(pkg);
41+
return get({
42+
url: 'http://localhost:49741/',
43+
headers: {
44+
Accept: 'text/html'
45+
}
46+
}).then(function(response) {
47+
expect(response.body).to.contain('Hello World! fetch');
48+
});
49+
});
50+
});

test/fixtures/dummy/app/app.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Application from '@ember/application';
2+
import Resolver from './resolver';
3+
import loadInitializers from 'ember-load-initializers';
4+
import config from './config/environment';
5+
6+
const App = Application.extend({
7+
modulePrefix: config.modulePrefix,
8+
podModulePrefix: config.podModulePrefix,
9+
Resolver
10+
});
11+
12+
loadInitializers(App, config.modulePrefix);
13+
14+
export default App;

test/fixtures/dummy/app/components/.gitkeep

Whitespace-only changes.

test/fixtures/dummy/app/controllers/.gitkeep

Whitespace-only changes.

test/fixtures/dummy/app/helpers/.gitkeep

Whitespace-only changes.

test/fixtures/dummy/app/index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Dummy</title>
7+
<meta name="description" content="">
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
10+
{{content-for "head"}}
11+
12+
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
13+
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/dummy.css">
14+
15+
{{content-for "head-footer"}}
16+
</head>
17+
<body>
18+
{{content-for "body"}}
19+
20+
<script src="{{rootURL}}assets/vendor.js"></script>
21+
<script src="{{rootURL}}assets/dummy.js"></script>
22+
23+
{{content-for "body-footer"}}
24+
</body>
25+
</html>

test/fixtures/dummy/app/models/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)