Skip to content

Commit

Permalink
Merge pull request #188 from zonkyio/tests-cleanup
Browse files Browse the repository at this point in the history
Tests cleanup
  • Loading branch information
bobisjan committed Jun 27, 2019
2 parents 30efe09 + ab22570 commit 41dba75
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 409 deletions.
197 changes: 88 additions & 109 deletions node-tests/acceptance/browserconfig-test.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,104 @@
'use strict';
const assert = require('assert');
const { AddonTestApp } = require('ember-cli-addon-tests');
const { contentOf, exists, assertJSON } = require('./helpers');

let assert = require('assert');
let fs = require('fs');
let AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
describe('Acceptance', function() {
describe('browserconfig', function() {
this.timeout(300000);

describe('Acceptance: browserconfig file generation', function() {
this.timeout(300000);
let app;

let app;
before(function() {
if (process.env.SKIP_ACCEPTANCE === 'true') {
this.skip();
return;
}

before(function() {
if (process.env.SKIP_ACCEPTANCE === 'true') {
this.skip();
return;
}
app = new AddonTestApp();
});

app = new AddonTestApp();
});

it('generates a browserconfig.xml file', function() {
return app
.create('empty', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(function() {
return app.runEmberCommand('build');
})
.then(contentOf(app, 'dist/browserconfig.xml'))
.then(function(content) {
assert.strictEqual(
content,
'<?xml version="1.0"?><browserconfig><msapplication/></browserconfig>'
it('generates a browserconfig.xml file', function() {
return app
.create('empty', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(() => app.runEmberCommand('build'))
.then(contentOf(app, 'dist/browserconfig.xml'))
.then(content =>
assert.strictEqual(
content,
'<?xml version="1.0"?><browserconfig><msapplication/></browserconfig>'
)
);
});
});
});

it('configures broccoli-asset-rev', function() {
return app
.create('dummy', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(function() {
return app.runEmberCommand('build', '--prod');
})
.then(contentOf(app, 'dist/browserconfig.xml'))
.then(function(content) {
assert.strictEqual(
content,
'<?xml version="1.0"?><browserconfig><msapplication><tile><square150x150logo src="pio-8911090226e7b5522790f1218f6924a5.png"/><TileColor>#FFFFFF</TileColor></tile></msapplication></browserconfig>'
);
})
.then(contentOf(app, 'dist/fastbootAssetMap.json'))
.then(assertJSON(app, { 'pio.png': 'pio-0987654321.png' }));
});
it('configures broccoli-asset-rev', function() {
return app
.create('dummy', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(() => app.runEmberCommand('build', '--prod'))
.then(contentOf(app, 'dist/browserconfig.xml'))
.then(content =>
assert.strictEqual(
content,
'<?xml version="1.0"?><browserconfig><msapplication><tile><square150x150logo src="pio-8911090226e7b5522790f1218f6924a5.png"/><TileColor>#FFFFFF</TileColor></tile></msapplication></browserconfig>'
)
)
.then(contentOf(app, 'dist/fastbootAssetMap.json'))
.then(assertJSON(app, { 'pio.png': 'pio-0987654321.png' }));
});

it(`doesn't generate browserconfig when tag is omitted`, function() {
return app
.create('no-browserconfig', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(function() {
return app.runEmberCommand('build');
})
.then(function() {
assert.ok(
!fs.existsSync(app.filePath('dist/browserconfig.xml')),
`Doesn't generate browserconfig.xml file`
it(`doesn't generate browserconfig when tag is omitted`, function() {
return app
.create('no-browserconfig', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(() => app.runEmberCommand('build'))
.then(() =>
assert.ok(
!exists(app, 'dist/browserconfig.xml'),
`Doesn't generate browserconfig.xml file`
)
)
.then(contentOf(app, 'dist/index.html'))
.then(content =>
assert.ok(
!content.includes('msapplication-config'),
`Doesn't include meta tags`
)
);
})
.then(contentOf(app, 'dist/index.html'))
.then(function(content) {
assert.ok(
!content.includes('msapplication-config'),
`Doesn't include meta tags`
);
});
});
});

it('uses rootURL configuration', function() {
return app
.create('config-root-url', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(function() {
return app.runEmberCommand('build');
})
.then(contentOf(app, 'dist/index.html'))
.then(function(content) {
assert.ok(
content.indexOf('content="/foo/bar/baz/browserconfig.xml"') > -1,
'index.html uses rootURL from configuration'
it('uses rootURL configuration', function() {
return app
.create('config-root-url', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(() => app.runEmberCommand('build'))
.then(contentOf(app, 'dist/index.html'))
.then(content =>
assert.ok(
content.indexOf('content="/foo/bar/baz/browserconfig.xml"') > -1,
'index.html uses rootURL from configuration'
)
);
});
});
});

it('uses fingerprint configuration for browserconfig', function() {
return app
.create('broccoli-asset-rev', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(function() {
return app.runEmberCommand('build', '--prod');
})
.then(contentOf(app, 'dist/browserconfig.xml'))
.then(function(content) {
assert.strictEqual(
content,
'<?xml version="1.0"?><browserconfig><msapplication><tile><square150x150logo src="https://www.example.com/pio-8911090226e7b5522790f1218f6924a5.png"/><TileColor>#FFFFFF</TileColor></tile></msapplication></browserconfig>'
it('uses fingerprint configuration for browserconfig', function() {
return app
.create('broccoli-asset-rev', {
fixturesPath: 'node-tests/acceptance/fixtures',
})
.then(() => app.runEmberCommand('build', '--prod'))
.then(contentOf(app, 'dist/browserconfig.xml'))
.then(content =>
assert.strictEqual(
content,
'<?xml version="1.0"?><browserconfig><msapplication><tile><square150x150logo src="https://www.example.com/pio-8911090226e7b5522790f1218f6924a5.png"/><TileColor>#FFFFFF</TileColor></tile></msapplication></browserconfig>'
)
);
});
});
});
});

function contentOf(app, path) {
return function() {
return fs.readFileSync(app.filePath(path), { encoding: 'utf-8' });
};
}

function assertJSON(app, expected) {
return function(actual) {
assert.deepStrictEqual(JSON.parse(actual), expected, 'assert JSON');
};
}
18 changes: 18 additions & 0 deletions node-tests/acceptance/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
const assert = require('assert');
const fs = require('fs');

module.exports = { contentOf, exists, assertJSON };

function contentOf(app, path) {
return () => fs.readFileSync(app.filePath(path), { encoding: 'utf-8' });
}

function exists(app, path) {
return fs.existsSync(app.filePath(path));
}

function assertJSON(app, expected) {
return actual =>
assert.deepStrictEqual(JSON.parse(actual), expected, 'assert JSON');
}

0 comments on commit 41dba75

Please sign in to comment.