Skip to content

Commit

Permalink
Merge pull request #778 from kiwiupover/move-package-json-test
Browse files Browse the repository at this point in the history
Move package-json test to the basic-app
  • Loading branch information
kratiahuja committed Aug 14, 2020
2 parents f80bcd8 + ff8dc4d commit b723a43
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 244 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"workspaces": [
"packages/ember-cli-fastboot",
"test-packages/basic-app"
"test-packages/basic-app",
"test-packages/*"
]
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

175 changes: 0 additions & 175 deletions packages/ember-cli-fastboot/test/package-json-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,170 +11,6 @@ chai.use(require('chai-fs'));
describe('generating package.json', function() {
this.timeout(300000);

let app;

before(function() {
app = new AddonTestApp();

return app.create('module-whitelist', {
skipNpm: true
})
.then(addFastBootDeps)
.then(function() {
return app.run('npm', 'install');
});
});

describe('with FastBoot builds', function() {

before(function() {
return app.runEmberCommand('build');
});

it('builds a package.json', function() {
expect(app.filePath('dist/package.json')).to.be.a.file();
});

it('merges FastBoot dependencies from multiple addons', function() {
let config = fs.readJsonSync(app.filePath('/dist/package.json'));

expect(config.dependencies).to.deep.equal({
'foo': '1.0.0',
'bar': '^0.1.2',
'baz': '0.0.0',
"najax": "^1.0.3",
'rsvp': '3.2.1'
});
});

it('contains a schema version', function() {
let pkg = fs.readJsonSync(app.filePath('/dist/package.json'));

expect(pkg.fastboot.schemaVersion).to.deep.equal(3);
});

it('contains a whitelist of allowed module names', function() {
let pkg = fs.readJsonSync(app.filePath('/dist/package.json'));

expect(pkg.fastboot.moduleWhitelist).to.deep.equal([
'najax',
'url',
'path',
'foo',
'bar',
'baz',
'rsvp'
]);
});

it('contains a manifest of FastBoot assets', function() {
let pkg = fs.readJsonSync(app.filePath('/dist/package.json'));

expect(pkg.fastboot.manifest).to.deep.equal({
appFiles: ['assets/module-whitelist.js', 'assets/module-whitelist-fastboot.js', 'ember-fastboot-build-example/bar.js'],
htmlFile: 'index.html',
vendorFiles: ['ember-fastboot-build-example/foo.js', 'assets/vendor.js']
});
});

it('contains a list of whitelisted hosts from environment.js', function() {
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));

expect(pkg.fastboot.hostWhitelist).to.deep.equal([
'example.com',
'subdomain.example.com',
'/localhost:\\d+/'
]);
});

it('contains app name', function() {
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));

expect(pkg.fastboot.appName).to.equal('module-whitelist');
});

it('contains the application config', function() {
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));

expect(pkg.fastboot.config['module-whitelist']).to.deep.equal({
modulePrefix: 'module-whitelist',
environment: 'development',
baseURL: '/',
locationType: 'auto',
EmberENV: { FEATURES: {} },
APP: { name: 'module-whitelist', version: '0.0.0', autoboot: false },
fastboot: { hostWhitelist: [ 'example.com', 'subdomain.example.com', '/localhost:\\d+/' ] },
exportApplicationGlobal: true
});
});

it('contains additional config from ember-fastboot-build-example addon', function() {
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));

expect(pkg.fastboot.config['foo']).to.equal('bar');
});

describe('with addon that implements fastbootConfigTree', function() {
let app;

before(function() {
app = new AddonTestApp();

return app.create('fastboot-config', {
skipNpm: true
})
.then(addFastBootDeps)
.then(function() {
return app.run('npm', 'install');
})
.then(function() {
return app.runEmberCommand('build');
});
});

it('it extends the application config', function() {
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));

expect(pkg.fastboot.config['fastboot-config']).to.deep.equal({
foo: 'bar',
modulePrefix: 'fastboot-config',
environment: 'development',
baseURL: '/',
locationType: 'auto',
EmberENV: { FEATURES: {} },
APP: { name: 'fastboot-config', version: '0.0.0', autoboot: false },
fastboot: { hostWhitelist: [ 'example.com', 'subdomain.example.com', '/localhost:\\d+/' ] },
exportApplicationGlobal: true
});
});
});
});

describe('with production FastBoot builds', function() {

before(function() {
return app.runEmberCommand('build', '--environment=production');
});

it('contains a manifest of FastBoot assets', function() {
let pkg = fs.readJsonSync(app.filePath('/dist/package.json'));

let p = function(filePath) {
return app.filePath(path.join('dist', filePath));
};

let manifest = pkg.fastboot.manifest;

manifest.appFiles.forEach(function(file) {
expect(p(file)).to.be.a.file();
});
expect(p(manifest.htmlFile)).to.be.a.file();
manifest.vendorFiles.forEach(function(file) {
expect(p(file)).to.be.a.file();
});
});
});

describe('with customized fingerprinting options', function() {
// Tests an app with a custom `assetMapPath` set
let customApp = new AddonTestApp();
Expand Down Expand Up @@ -276,14 +112,3 @@ describe('generating package.json', function() {
});
});

function addFastBootDeps(app) {
return app.editPackageJSON(pkg => {
pkg['devDependencies']['fake-addon'] = `*`;
pkg['devDependencies']['fake-addon-2'] = `*`;
pkg['fastbootDependencies'] = ["rsvp"];
pkg['dependencies'] = {
rsvp: '3.2.1',
'ember-fastboot-build-example': '0.1.2'
};
});
}
8 changes: 8 additions & 0 deletions test-packages/basic-app/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module.exports = function(environment) {
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},

fastboot: {
hostWhitelist: [
'example.com',
'subdomain.example.com',
'/localhost:\\d+/',
]
}
};

Expand Down
9 changes: 9 additions & 0 deletions test-packages/basic-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"test:ember": "ember test",
"test:mocha": "mocha"
},
"dependencies": {
"ember-fastboot-build-example": "0.1.2",
"rsvp": "^4.8.5"
},
"devDependencies": {
"@ember/optional-features": "^1.3.0",
"@glimmer/component": "^1.0.0",
Expand Down Expand Up @@ -53,11 +57,16 @@
"eslint-plugin-ember": "^8.6.0",
"eslint-plugin-node": "^11.1.0",
"execa": "^4.0.3",
"fake-addon": "*",
"fake-addon-2": "*",
"loader.js": "^4.7.0",
"mocha": "^8.0.1",
"npm-run-all": "^4.1.5",
"qunit-dom": "^1.2.0"
},
"fastbootDependencies": [
"rsvp"
],
"engines": {
"node": "10.* || >= 12"
},
Expand Down
Loading

0 comments on commit b723a43

Please sign in to comment.