1 | const expect = require('chai').expect;
|
2 | const denodeify = require('denodeify');
|
3 | const request = denodeify(require('request'));
|
4 | const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
|
5 | const path = require('path');
|
6 | const fs = require('fs-extra');
|
7 |
|
8 | const testEmberVersions = ['beta', 'latest', '3.12', '3.8', '3.4', '2.18'];
|
9 |
|
10 | testEmberVersions.forEach(version => {
|
11 | describe(`basic registration in Ember version "${version}"`, function() {
|
12 | this.timeout(10000000);
|
13 | let app;
|
14 |
|
15 | before(function() {
|
16 | app = new AddonTestApp();
|
17 |
|
18 | return app.create('dummy', {
|
19 | emberVersion: version,
|
20 | fixturesPath: 'node-tests/fixtures',
|
21 | skipNpm: true
|
22 | })
|
23 | .then(() => {
|
24 | app.editPackageJSON(pkg => {
|
25 | pkg['ember-addon'] = pkg['ember-addon'] || {};
|
26 | pkg['ember-addon'].paths = pkg['ember-addon'].paths || [];
|
27 | pkg['ember-addon'].paths.push('lib/ember-service-worker-test');
|
28 | });
|
29 | return app.run('npm', 'install');
|
30 | }).then(() => {
|
31 |
|
32 | let addonPath = path.join(app.path, 'node_modules', 'ember-service-worker');
|
33 | fs.removeSync(addonPath);
|
34 | fs.ensureSymlinkSync(process.cwd(), addonPath);
|
35 | }).then(() => {
|
36 | return app.startServer({
|
37 | detectServerStart(output) {
|
38 | return output.indexOf('Serving on ') > -1;
|
39 | }
|
40 | });
|
41 | });
|
42 | });
|
43 |
|
44 | after(function() {
|
45 | return app.stopServer();
|
46 | });
|
47 |
|
48 | it('includes registration in script tag by default', () => {
|
49 | return request({
|
50 | url: 'http://localhost:49741',
|
51 | headers: {
|
52 | 'Accept': 'text/html'
|
53 | }
|
54 | }).then(response => {
|
55 | expect(response.statusCode).to.equal(200);
|
56 | expect(response.body).to.contain('<script src="/sw-registration.js"');
|
57 | });
|
58 | });
|
59 |
|
60 | it('produces a sw-registration.js file', () => {
|
61 | return request({
|
62 | url: 'http://localhost:49741/sw-registration.js'
|
63 | }).then(response => {
|
64 | expect(response.statusCode).to.equal(200);
|
65 | expect(response.body).to.contain('self.hello');
|
66 | });
|
67 | });
|
68 |
|
69 | it('produces a sw.js file', () => {
|
70 | return request({
|
71 | url: 'http://localhost:49741/sw.js'
|
72 | }).then(response => {
|
73 | expect(response.statusCode).to.equal(200);
|
74 | expect(response.body).to.contain('self.hello');
|
75 | });
|
76 | });
|
77 | });
|
78 | });
|