Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null check for calculateToString method #16478

Closed
wants to merge 12 commits into from
Closed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tmp.bpm
tmp.spade
tests/source
node_modules
yarn-error.log
bundle/
*~
publish_to_bower/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ branches:
only:
- master
- beta
- stable
- release
# npm version tags
- /^v\d+\.\d+\.\d+/

Expand Down
83 changes: 46 additions & 37 deletions bin/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var path = require('path');
var finalhandler = require('finalhandler');
var http = require('http');
var serveStatic = require('serve-static');
var puppeteer = require('puppeteer');

// Serve up public/ftp folder.
var serve = serveStatic('./dist/', { index: ['index.html', 'index.htm'] });
Expand All @@ -28,6 +29,9 @@ var PORT = 13141;
// Listen.
server.listen(PORT);

// Cache the Chrome browser instance when launched for new pages.
var browserPromise;

function run(queryString) {
return new RSVP.Promise(function(resolve, reject) {
var url = 'http://localhost:' + PORT + '/tests/?' + queryString;
Expand All @@ -40,9 +44,11 @@ function runInBrowser(url, retries, resolve, reject) {

console.log('Running Chrome headless: ' + url);

var puppeteer = require('puppeteer');
if (!browserPromise) {
browserPromise = puppeteer.launch();
}

puppeteer.launch().then(function(browser) {
browserPromise.then(function(browser) {
browser.newPage().then(function(page) {
/* globals window */
var crashed;
Expand Down Expand Up @@ -136,52 +142,55 @@ function runInBrowser(url, retries, resolve, reject) {
' failed.'
);

if (typeof window.callPhantom === 'function') {
window.callPhantom({
name: 'QUnit.done',
data: result,
});
}
window.callPhantom({
name: 'QUnit.done',
data: result,
});
});
});
};

page.exposeFunction('callPhantom', function(message) {
if (message && message.name === 'QUnit.done') {
result = message.data;
var failed = !result || !result.total || result.failed;
return page
.exposeFunction('callPhantom', function(message) {
page.close();

if (!result.total) {
console.error('No tests were executed. Are you loading tests asynchronously?');
}
if (message && message.name === 'QUnit.done') {
result = message.data;
var failed = !result || !result.total || result.failed;

var code = failed ? 1 : 0;
result.code = code;
if (!result.total) {
console.error('No tests were executed. Are you loading tests asynchronously?');
}

if (!crashed && code === 0) {
resolve(result);
} else if (crashed) {
console.log(chalk.red('Browser crashed with exit code ' + code));
var code = failed ? 1 : 0;
result.code = code;

if (retries > 1) {
console.log(chalk.yellow('Retrying... ¯_(ツ)_/¯'));
runInBrowser(url, retries - 1, resolve, reject);
} else {
console.log(chalk.red('Giving up! (╯°□°)╯︵ ┻━┻'));
console.log(
chalk.yellow('This might be a known issue with Chrome headless, skipping for now')
);
if (!crashed && code === 0) {
resolve(result);
} else if (crashed) {
console.log(chalk.red('Browser crashed with exit code ' + code));

if (retries > 1) {
console.log(chalk.yellow('Retrying... ¯\\_(ツ)_/¯'));
runInBrowser(url, retries - 1, resolve, reject);
} else {
console.log(chalk.red('Giving up! (╯°□°)╯︵ ┻━┻'));
console.log(
chalk.yellow('This might be a known issue with Chrome headless, skipping for now')
);
resolve(result);
}
} else {
reject(result);
}
} else {
reject(result);
}
}
});

page.evaluateOnNewDocument(addLogging);

page.goto(url, { timeout: 900 });
})
.then(function() {
return page.evaluateOnNewDocument(addLogging);
})
.then(function() {
return page.goto(url, { timeout: 900 });
});
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, beforeEach, afterEach } from 'mocha';
import { run } from '@ember/runloop';
import Application from '@ember/application';
import { initialize } from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>';
import destroyApp from '../../helpers/destroy-app';
<% if (destroyAppExists) { %>import destroyApp from '../../helpers/destroy-app';<% } %>

describe('<%= friendlyTestName %>', function() {
let application;
Expand All @@ -16,7 +16,7 @@ describe('<%= friendlyTestName %>', function() {
});

afterEach(function() {
destroyApp(application);
<% if (destroyAppExists) { %>destroyApp(application);<% } else { %>run(application, 'destroy');<% } %>
});

// Replace this with your real tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { run } from '@ember/runloop';

import { initialize } from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>';
import { module, test } from 'qunit';
<% if (destroyAppExists) { %>import destroyApp from '../../helpers/destroy-app';<% } else { %>import { run } from '@ember/runloop'; <% } %>
<% if (destroyAppExists) { %>import destroyApp from '../../helpers/destroy-app';<% } %>

module('<%= friendlyTestName %>', {
beforeEach() {
Expand Down
30 changes: 29 additions & 1 deletion blueprints/service-test/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
'use strict';

const useTestFrameworkDetector = require('../test-framework-detector');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;

module.exports = useTestFrameworkDetector({
description: 'Generates a service unit test.',
locals: function(options) {

fileMapTokens() {
if (isModuleUnificationProject(this.project)) {
return {
__root__(options) {
if (options.pod) {
throw "Pods aren't supported within a module unification app";
}

return 'src';
},
__testType__() {
return '';
},
};
} else {
return {
__root__() {
return 'tests';
},
__testType__() {
return 'unit';
},
};
}
},

locals(options) {
return {
friendlyTestDescription: ['Unit', 'Service', options.entity.name].join(' | '),
};
Expand Down
16 changes: 16 additions & 0 deletions blueprints/service/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
'use strict';

const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;

module.exports = {
description: 'Generates a service.',

fileMapTokens() {
if (isModuleUnificationProject(this.project)) {
return {
__root__(options) {
if (options.pod) {
throw "Pods aren't supported within a module unification app";
}

return 'src';
},
};
}
},
};
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = {
files: ['jquery.js'],
});

let emberSourceDistPath = path.join(__dirname, '..', 'dist');
var emberFiles = [
'ember-runtime.js',
'ember-template-compiler.js',
Expand All @@ -81,12 +82,12 @@ module.exports = {
return flat.concat(jsAndMap);
}, [])
.filter(function(file) {
var fullPath = path.join(__dirname, '..', 'dist', file);
var fullPath = path.join(emberSourceDistPath, file);

return fs.existsSync(fullPath);
});

var ember = new Funnel(__dirname + '../dist', {
var ember = new Funnel(emberSourceDistPath, {
destDir: 'ember',
files: emberFiles,
});
Expand Down
11 changes: 1 addition & 10 deletions node-tests/blueprints/component-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,14 @@ const emberNew = blueprintHelpers.emberNew;
const emberGenerate = blueprintHelpers.emberGenerate;
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
const modifyPackages = blueprintHelpers.modifyPackages;
const expectError = require('../helpers/expect-error');

const chai = require('ember-cli-blueprint-test-helpers/chai');
const expect = chai.expect;

const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
const fixture = require('../helpers/fixture');

function expectError(promise, expectedErrorText) {
return promise
.then(() => {
throw 'the command should raise an exception';
})
.catch(error => {
expect(error).to.equal(expectedErrorText);
});
}

describe('Blueprint: component-test', function() {
setupTestHooks(this);

Expand Down
73 changes: 73 additions & 0 deletions node-tests/blueprints/service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const setupTestHooks = blueprintHelpers.setupTestHooks;
const emberNew = blueprintHelpers.emberNew;
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
const setupPodConfig = blueprintHelpers.setupPodConfig;
const expectError = require('../helpers/expect-error');

const chai = require('ember-cli-blueprint-test-helpers/chai');
const expect = chai.expect;
const fs = require('fs-extra');

describe('Blueprint: service', function() {
setupTestHooks(this);
Expand Down Expand Up @@ -96,6 +98,43 @@ describe('Blueprint: service', function() {
});
});

describe('in app - module unification', function() {
beforeEach(function() {
return emberNew().then(() => fs.ensureDirSync('src'));
});

it('service foo', function() {
return emberGenerateDestroy(['service', 'foo'], _file => {
expect(_file('src/services/foo.js'))
.to.contain("import Service from '@ember/service';")
.to.contain('export default Service.extend({\n});');

expect(_file('src/services/foo-test.js'))
.to.contain("import { moduleFor, test } from 'ember-qunit';")
.to.contain("moduleFor('service:foo'");
});
});

it('service foo/bar', function() {
return emberGenerateDestroy(['service', 'foo/bar'], _file => {
expect(_file('src/services/foo/bar.js'))
.to.contain("import Service from '@ember/service';")
.to.contain('export default Service.extend({\n});');

expect(_file('src/services/foo/bar-test.js'))
.to.contain("import { moduleFor, test } from 'ember-qunit';")
.to.contain("moduleFor('service:foo/bar'");
});
});

it('service foo --pod', function() {
return expectError(
emberGenerateDestroy(['service', 'foo', '--pod']),
"Pods aren't supported within a module unification app"
);
});
});

describe('in addon', function() {
beforeEach(function() {
return emberNew({ target: 'addon' });
Expand Down Expand Up @@ -133,4 +172,38 @@ describe('Blueprint: service', function() {
});
});
});

describe('in addon - module unification', function() {
beforeEach(function() {
return emberNew({ target: 'addon' }).then(() => fs.ensureDirSync('src'));
});

it('service foo', function() {
return emberGenerateDestroy(['service', 'foo'], _file => {
expect(_file('src/services/foo.js'))
.to.contain("import Service from '@ember/service';")
.to.contain('export default Service.extend({\n});');

expect(_file('src/services/foo-test.js'))
.to.contain("import { moduleFor, test } from 'ember-qunit';")
.to.contain("moduleFor('service:foo'");

expect(_file('app/services/foo.js')).to.not.exist;
});
});

it('service foo/bar', function() {
return emberGenerateDestroy(['service', 'foo/bar'], _file => {
expect(_file('src/services/foo/bar.js'))
.to.contain("import Service from '@ember/service';")
.to.contain('export default Service.extend({\n});');

expect(_file('src/services/foo/bar-test.js'))
.to.contain("import { moduleFor, test } from 'ember-qunit';")
.to.contain("moduleFor('service:foo/bar'");

expect(_file('app/services/foo/bar.js')).to.not.exist;
});
});
});
});
4 changes: 2 additions & 2 deletions node-tests/fixtures/acceptance-test/mocha.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from 'my-app/tests/helpers/start-app';
import destroyApp from 'my-app/tests/helpers/destroy-app';
import { run } from '@ember/runloop';

describe('Acceptance | foo', function() {
let application;
Expand All @@ -11,7 +11,7 @@ describe('Acceptance | foo', function() {
});

afterEach(function() {
destroyApp(application);
run(application, 'destroy');
});

it('can visit /foo', function() {
Expand Down
Loading