Skip to content

Commit fcf0c9a

Browse files
committed
Setup addon tests
use npm run instead of yarn in travis to work around tomdale/ember-cli-addon-tests#198
1 parent 046f8f7 commit fcf0c9a

File tree

25 files changed

+385
-7
lines changed

25 files changed

+385
-7
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

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
script:
3636
- yarn lint:js
3737
- yarn test
38-
- yarn test:node
38+
- npm run test:node
3939

4040
- name: "Floating Dependencies"
4141
script:

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
"broccoli-asset-rev": "^3.0.0",
3838
"broccoli-test-helper": "^2.0.0",
3939
"chai": "^4.1.2",
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-htmlbars": "^3.0.1",
4446
"ember-cli-fastboot": "^2.0.0",
@@ -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"

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+
beforeEach(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+
beforeEach(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+
afterEach(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>

0 commit comments

Comments
 (0)