Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Get tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav0 committed Oct 15, 2018
1 parent 656c06b commit cb87057
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module.exports = {
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'lib/**/*.js',
'node_tests/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
Expand Down
50 changes: 50 additions & 0 deletions lib/displayutils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

var util = require('util');

// Method to format test results.
var strutils = require('./strutils');

function resultDisplay(id, prefix, result) {

var parts = [];
if (prefix) {
parts.push(prefix);
}
if (result.name) {
parts.push(result.name.trim());
}

var line = parts.join(' - ');
return (result.skipped ? 'skip ' : (result.passed ? 'ok ' : 'not ok ')) + id + ' ' + line;
}

function yamlDisplay(err, logs) {
var testLogs;
var failed = Object.keys(err || {})
.filter(function(key) {
return key !== 'passed';
})
.map(function(key) {
return key + ': >\n' + strutils.indent(String(err[key]));
});
if (logs) {
testLogs = ['Log: |'].concat(logs.map(function(log) {return strutils.indent(util.inspect(log));}));
} else {
testLogs = [];
}
return strutils.indent([
'---',
strutils.indent(failed.concat(testLogs).join('\n')),
'...'].join('\n'));
}

function resultString(id, prefix, result, quietLogs) {
var string = resultDisplay(id, prefix, result) + '\n';
if (result.error || (!quietLogs && result.logs && result.logs.length)) {
string += yamlDisplay(result.error, result.logs) + '\n';
}
return string;
}

exports.resultString = resultString;
62 changes: 62 additions & 0 deletions lib/old-tap-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copied from https://github.com/testem/testem/blob/79e75d850942804e197d4bb676b9cbc5c4026b53/lib/reporters/tap_reporter.js
'use strict';

var displayutils = require('./displayutils');

function TapReporter(silent, out, config) {
this.out = out || process.stdout;
this.silent = silent;
this.quietLogs = !!config.get('tap_quiet_logs');
this.stoppedOnError = null;
this.id = 1;
this.total = 0;
this.pass = 0;
this.skipped = 0;
this.results = [];
this.errors = [];
this.logs = [];
}
TapReporter.prototype = {
report: function(prefix, data) {
this.results.push({
launcher: prefix,
result: data
});
this.display(prefix, data);
this.total++;
if (data.skipped) {
this.skipped++;
} else if (data.passed) {
this.pass++;
}
},
summaryDisplay: function() {
var lines = [
'1..' + this.total,
'# tests ' + this.total,
'# pass ' + this.pass,
'# skip ' + this.skipped,
'# fail ' + (this.total - this.pass - this.skipped)
];

if (this.pass + this.skipped === this.total) {
lines.push('');
lines.push('# ok');
}
return lines.join('\n');
},
display: function(prefix, result) {
if (this.silent) {
return;
}
this.out.write(displayutils.resultString(this.id++, prefix, result, this.quietLogs));
},
finish: function() {
if (this.silent) {
return;
}
this.out.write('\n' + this.summaryDisplay() + '\n');
}
};

module.exports = TapReporter;
45 changes: 45 additions & 0 deletions lib/strutils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

// String padding function adapted from <http://jsfromhell.com/string/pad>
function pad(str, l, s, t) {
var ol = l;
return (s || (s = ' '), (l -= str.length) > 0 ?
(s = new Array(Math.ceil(l / s.length) + 1).join(s))
.substr(0, t = !t ? l : t === 1 ? 0 :
Math.ceil(l / 2)) + str + s.substr(0, l - t) : str).substring(0, ol);
}

function indent(text, width) {
return text.split('\n').map(function(line) {
return new Array((width || 4) + 1).join(' ') + line;
}).join('\n');
}

function splitLines(text, colLimit) {
if (!text) {
return [];
}
var firstSplit = text.split('\n');
var secondSplit = [];
firstSplit.forEach(function(line) {
while (line.length > colLimit) {
var first = line.substring(0, colLimit);
secondSplit.push(first);
line = line.substring(colLimit);
}
secondSplit.push(line);
});
return secondSplit;
}

// Simple template function. Replaces occurences of "<name>" with param[name]
function template(str, params) {
return !str.replace ? str : str.replace(/<(.+?)>/g, function(unchanged, name) {
return name in params ? params[name] : unchanged;
});
}

exports.pad = pad;
exports.indent = indent;
exports.splitLines = splitLines;
exports.template = template;
6 changes: 3 additions & 3 deletions node-tests/blueprints/ember-cli-eslint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Acceptance: install ember-cli-eslint', function() {
it('removes the JSHint addon', function() {
var args = ['ember-cli-eslint', 'foo'];

td.when(prompt(td.matchers.anything())).thenResolve({ deleteFiles: 'all' });
td.when(prompt(td.matchers.anything())).thenResolve({ answer: 'overwrite', deleteFiles: 'all' });

return emberNew()
.then(function() {
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Acceptance: install ember-cli-eslint', function() {
path.join('.', 'tests', 'dummy', 'app', 'dist', '.jshintrc')
];

td.when(prompt(td.matchers.anything())).thenResolve({ deleteFiles: 'all' });
td.when(prompt(td.matchers.anything())).thenResolve({ answer: 'overwrite', deleteFiles: 'all' });

return emberNew()
.then(function() {
Expand All @@ -109,7 +109,7 @@ describe('Acceptance: install ember-cli-eslint', function() {
it('does not remove any files if it shouldn\'t', function() {
var args = ['ember-cli-eslint', 'foo'];

td.when(prompt(td.matchers.anything())).thenResolve({ deleteFiles: 'none' });
td.when(prompt(td.matchers.anything())).thenResolve({ answer: 'overwrite', deleteFiles: 'none' });

return emberNew()
.then(function() {
Expand Down
43 changes: 20 additions & 23 deletions node-tests/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var fs = require('fs-extra');
var exec = require('child_process').exec;

Expand Down Expand Up @@ -28,13 +30,12 @@ describe('ember-cli-eslint', function() {
.to.contain(`ok 2 ${browser} - ESLint | controllers/thing.js: should pass ESLint`)
.to.contain(`ok 3 ${browser} - ESLint | helpers/destroy-app.js: should pass ESLint`)
.to.contain(`ok 4 ${browser} - ESLint | helpers/module-for-acceptance.js: should pass ESLint`)
.to.contain(`ok 5 ${browser} - ESLint | helpers/resolver.js: should pass ESLint`)
.to.contain(`ok 6 ${browser} - ESLint | helpers/start-app.js: should pass ESLint`)
.to.contain(`ok 7 ${browser} - ESLint | models/thing.js: should pass ESLint`)
.to.contain(`ok 8 ${browser} - ESLint | resolver.js: should pass ESLint`)
.to.contain(`ok 9 ${browser} - ESLint | router.js: should pass ESLint`)
.to.contain(`ok 10 ${browser} - ESLint | test-helper.js: should pass ESLint`)
.to.not.contain(`not ok 11 ${browser} - ESLint | unused.js: should pass ESLint`);
.to.contain(`ok 5 ${browser} - ESLint | helpers/start-app.js: should pass ESLint`)
.to.contain(`ok 6 ${browser} - ESLint | models/thing.js: should pass ESLint`)
.to.contain(`ok 7 ${browser} - ESLint | resolver.js: should pass ESLint`)
.to.contain(`ok 8 ${browser} - ESLint | router.js: should pass ESLint`)
.to.contain(`ok 9 ${browser} - ESLint | test-helper.js: should pass ESLint`)
.to.not.contain(`not ok 10 ${browser} - ESLint | unused.js: should pass ESLint`);
})
});

Expand All @@ -50,13 +51,12 @@ describe('ember-cli-eslint', function() {
.to.contain(`ok 2 ${browser} - ESLint | controllers/thing.js: should pass ESLint`)
.to.contain(`ok 3 ${browser} - ESLint | helpers/destroy-app.js: should pass ESLint`)
.to.contain(`ok 4 ${browser} - ESLint | helpers/module-for-acceptance.js: should pass ESLint`)
.to.contain(`ok 5 ${browser} - ESLint | helpers/resolver.js: should pass ESLint`)
.to.contain(`ok 6 ${browser} - ESLint | helpers/start-app.js: should pass ESLint`)
.to.contain(`ok 7 ${browser} - ESLint | models/thing.js: should pass ESLint`)
.to.contain(`ok 8 ${browser} - ESLint | resolver.js: should pass ESLint`)
.to.contain(`ok 9 ${browser} - ESLint | router.js: should pass ESLint`)
.to.contain(`ok 10 ${browser} - ESLint | test-helper.js: should pass ESLint`)
.to.contain(`not ok 11 ${browser} - ESLint | unused.js: should pass ESLint`);
.to.contain(`ok 5 ${browser} - ESLint | helpers/start-app.js: should pass ESLint`)
.to.contain(`ok 6 ${browser} - ESLint | models/thing.js: should pass ESLint`)
.to.contain(`ok 7 ${browser} - ESLint | resolver.js: should pass ESLint`)
.to.contain(`ok 8 ${browser} - ESLint | router.js: should pass ESLint`)
.to.contain(`ok 9 ${browser} - ESLint | test-helper.js: should pass ESLint`)
.to.contain(`not ok 10 ${browser} - ESLint | unused.js: should pass ESLint`);
})
});

Expand All @@ -76,9 +76,8 @@ describe('ember-cli-eslint', function() {
expect(result.stdout.match(/[^\r\n]+/g))
.to.contain(`ok 6 ${browser} - ESLint | tests: helpers/destroy-app.js`)
.to.contain(`ok 7 ${browser} - ESLint | tests: helpers/module-for-acceptance.js`)
.to.contain(`ok 8 ${browser} - ESLint | tests: helpers/resolver.js`)
.to.contain(`ok 9 ${browser} - ESLint | tests: helpers/start-app.js`)
.to.contain(`ok 10 ${browser} - ESLint | tests: test-helper.js`);
.to.contain(`ok 8 ${browser} - ESLint | tests: helpers/start-app.js`)
.to.contain(`ok 9 ${browser} - ESLint | tests: test-helper.js`);
})
});

Expand All @@ -100,9 +99,8 @@ describe('ember-cli-eslint', function() {
expect(result.stdout.match(/[^\r\n]+/g))
.to.contain(`ok 7 ${browser} - ESLint | tests: helpers/destroy-app.js`)
.to.contain(`ok 8 ${browser} - ESLint | tests: helpers/module-for-acceptance.js`)
.to.contain(`ok 9 ${browser} - ESLint | tests: helpers/resolver.js`)
.to.contain(`ok 10 ${browser} - ESLint | tests: helpers/start-app.js`)
.to.contain(`ok 11 ${browser} - ESLint | tests: test-helper.js`);
.to.contain(`ok 9 ${browser} - ESLint | tests: helpers/start-app.js`)
.to.contain(`ok 10 ${browser} - ESLint | tests: test-helper.js`);
})
});

Expand All @@ -123,9 +121,8 @@ describe('ember-cli-eslint', function() {
expect(result.stdout.match(/[^\r\n]+/g))
.to.contain(`ok 7 ${browser} - ESLint | tests: helpers/destroy-app.js`)
.to.contain(`ok 8 ${browser} - ESLint | tests: helpers/module-for-acceptance.js`)
.to.contain(`ok 9 ${browser} - ESLint | tests: helpers/resolver.js`)
.to.contain(`ok 10 ${browser} - ESLint | tests: helpers/start-app.js`)
.to.contain(`ok 11 ${browser} - ESLint | tests: test-helper.js`);
.to.contain(`ok 9 ${browser} - ESLint | tests: helpers/start-app.js`)
.to.contain(`ok 10 ${browser} - ESLint | tests: test-helper.js`);
})
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"chai": "^4.0.2",
"ember-cli": "~3.4.3",
"ember-cli-babel": "^6.16.0",
"ember-cli-blueprint-test-helpers": "^0.18.0",
"ember-cli-blueprint-test-helpers": "^0.19.1",
"ember-cli-dependency-checker": "^3.0.0",
"ember-cli-htmlbars": "^3.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
Expand Down
7 changes: 5 additions & 2 deletions testem.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
var CustomReporter = require('./lib/old-tap-reporter');

module.exports = {
"test_page": "tests/index.html?hidepassed",
"disable_watching": true,
"reporter": CustomReporter,
"launch_in_ci": [
"Chrome"
],
launch_in_dev: [
'Chrome'
"launch_in_dev": [
"Chrome"
],
browser_args: {
Chrome: {
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy/app/routes/thing.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ember from 'ember';
import Route from '@ember/routing/route';

export default Ember.Route.extend({
export default Route.extend({
});
Loading

0 comments on commit cb87057

Please sign in to comment.