Skip to content

Commit dfd6e73

Browse files
committed
Setup addon tests
1 parent 3b8e4ad commit dfd6e73

File tree

24 files changed

+386
-8
lines changed

24 files changed

+386
-8
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
/.node_modules.ember-try/
1818
/bower.json.ember-try
1919
/package.json.ember-try
20+
21+
test/fixtures

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
"devDependencies": {
3636
"broccoli-asset-rev": "^2.4.5",
3737
"broccoli-test-helper": "^1.2.0",
38-
"chai": "^4.1.2",
38+
"chai": "^4.2.0",
39+
"chai-fs": "^2.0.0",
3940
"co": "^4.6.0",
4041
"ember-cli": "~3.5.1",
42+
"ember-cli-addon-tests": "^0.11.0",
4143
"ember-cli-dependency-checker": "^3.0.0",
4244
"ember-cli-htmlbars": "^3.0.1",
4345
"ember-cli-fastboot": "^2.0.0",
@@ -57,6 +59,8 @@
5759
"eslint": "^5.9.0",
5860
"eslint-plugin-ember": "^6.0.1",
5961
"eslint-plugin-node": "^8.0.0",
62+
"fs-extra": "^7.0.1",
63+
"glob": "^7.1.3",
6064
"lerna-changelog": "^0.8.2",
6165
"loader.js": "^4.2.3",
6266
"mocha": "^5.2.0"

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/fastboot-fetch.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/fastboot-fetch-*.js')).to.be.a.file();
42+
expect(find('dist/ember-fetch/fastboot-fetch-*.js')).to.match(
43+
/fastboot-fetch-\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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
const request = require('request');
3+
const get = require('rsvp').denodeify(request);
4+
const chai = require('chai');
5+
const expect = chai.expect;
6+
chai.use(require('chai-fs'));
7+
8+
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
9+
10+
describe('renders in fastboot build', 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+
// These 2 are in ember-fetch's package.json, symlinking to dummy won't help resolve
24+
pkg.devDependencies['abortcontroller-polyfill'] = '*';
25+
pkg.devDependencies['node-fetch'] = '*';
26+
})
27+
)
28+
.then(function() {
29+
return app.run('npm', 'install');
30+
})
31+
.then(function() {
32+
return app.startServer({
33+
command: 'serve'
34+
});
35+
});
36+
});
37+
38+
after(function() {
39+
return app.stopServer();
40+
});
41+
42+
it('fetches in fastboot mode', function() {
43+
return get({
44+
url: 'http://localhost:49741/',
45+
headers: {
46+
Accept: 'text/html'
47+
}
48+
}).then(function(response) {
49+
expect(response.body).to.contain('Hello World! fetch');
50+
});
51+
});
52+
});

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)