diff --git a/.publishrc b/.publishrc new file mode 100644 index 0000000..e6d9ee8 --- /dev/null +++ b/.publishrc @@ -0,0 +1,13 @@ +{ + "validations": { + "vulnerableDependencies": true, + "uncommittedChanges": true, + "untrackedFiles": true, + "sensitiveData": true, + "branch": "master", + "gitTag": true + }, + "confirm": true, + "publishTag": "latest", + "prePublishScript": "npm test" +} \ No newline at end of file diff --git a/generators/app/templates/Gulpfile.js b/generators/app/templates/Gulpfile.js index 702df7f..3714217 100644 --- a/generators/app/templates/Gulpfile.js +++ b/generators/app/templates/Gulpfile.js @@ -3,7 +3,6 @@ var eslint = require('gulp-eslint'); var babel = require('gulp-babel'); var mocha = require('gulp-mocha'); var del = require('del'); -var publish = require('publish-please'); gulp.task('clean', function (cb) { del('lib', cb); @@ -39,20 +38,16 @@ gulp.task('test', ['build'], function () { }); gulp.task('preview', ['build'], function () { - var pluginTestingUtils = require('testcafe').pluginTestingUtils; - var pluginFactory = require('./lib'); - var testCalls = require('./test/data/test-calls'); - var plugin = pluginTestingUtils.buildReporterPlugin(pluginFactory); + var buildReporterPlugin = require('testcafe').embeddingUtils.buildReporterPlugin; + var pluginFactory = require('./lib'); + var reporterTestCalls = require('./test/utils/reporter-test-calls'); + var plugin = buildReporterPlugin(pluginFactory); console.log(); - testCalls.forEach(function (call) { + reporterTestCalls.forEach(function (call) { plugin[call.method].apply(plugin, call.args); }); process.exit(0); }); - -gulp.task('publish', ['test'], function () { - return publish(); -}); diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json index a8ac0cc..e9aa4c0 100644 --- a/generators/app/templates/_package.json +++ b/generators/app/templates/_package.json @@ -13,7 +13,9 @@ "lib" ], "scripts": { - "test": "gulp test" + "test": "gulp test", + "publish-please": "publish-please", + "prepublish": "publish-please guard" }, "keywords": [ "testcafe", @@ -23,6 +25,7 @@ "license": "MIT", "devDependencies": { "babel-eslint": "^4.0.10", + "callsite-record": "^3.2.0", "del": "^1.2.0", "gulp": "^3.9.0", "gulp-babel": "^5.2.1", @@ -30,7 +33,8 @@ "gulp-mocha": "^2.2.0", "normalize-newline": "^1.0.2", "publish-please": "^1.0.1", + "publish-please": "^2.1.4", "read-file-relative": "^1.2.0", - "testcafe": "0.0.7-alpha" + "testcafe": "^0.0.21" } } diff --git a/generators/app/templates/test/data/test-calls.js b/generators/app/templates/test/data/test-calls.js deleted file mode 100644 index a331ca1..0000000 --- a/generators/app/templates/test/data/test-calls.js +++ /dev/null @@ -1,151 +0,0 @@ -module.exports = [ - { - method: 'reportTaskStart', - args: [ - new Date('1970-01-01T00:00:00.000Z'), - [ - 'Chrome', - 'Firefox' - ], - 6 - ] - }, - { - method: 'reportFixtureStart', - args: [ - 'fixture1', - './fixture1.js' - ] - }, - { - method: 'reportTestDone', - args: [ - 'fixture1test1', - [], - 74000, - true, - '/screenshots/1445437598847' - ] - }, - { - method: 'reportTestDone', - args: [ - 'fixture1test2', - [ - { - stepName: 'Step', - expected: '"12345678901"', - actual: '"00000000000"', - relatedSourceCode: 'eq(["12345678901"], ["00000000000"])', - key: 0, - isArrays: true, - type: 'eqAssertion', - - diffType: { - isStrings: true, - diffIndex: 0 - }, - - screenshotPath: '/screenshots/1445437598847/userAgent/1.Fail.png', - userAgent: 'Chrome' - }, - { - relatedSourceCode: 'notEq("test", "test")', - actual: '"test"', - expected: '"test"', - stepName: 'Step', - type: 'notEqAssertion', - userAgent: 'Chrome' - }, - { - stepName: 'Step', - relatedSourceCode: 'ok(false)', - actual: 'false', - type: 'okAssertion', - userAgent: 'Firefox' - } - ], - 74000, - false, - '/screenshots/1445437598847' - ] - }, - { - method: 'reportTestDone', - args: [ - 'fixture1test3', - [], - 74000, - false, - null - ] - }, - { - method: 'reportFixtureStart', - args: [ - 'fixture2', - './fixture2.js' - ] - }, - { - method: 'reportTestDone', - args: [ - 'fixture2test1', - [], - 74000, - false, - null - ] - }, - { - method: 'reportTestDone', - args: [ - 'fixture2test2', - [], - 74000, - false, - null - ] - }, - { - method: 'reportFixtureStart', - args: [ - 'fixture3', - './fixture3.js' - ] - }, - { - method: 'reportTestDone', - args: [ - 'fixture3test1', - [ - { - stepName: 'Step', - expected: '"12345678901"', - actual: '"00000000000"', - relatedSourceCode: 'eq(["12345678901"], ["00000000000"])', - key: 0, - isArrays: true, - type: 'eqAssertion', - - diffType: { - isStrings: true, - diffIndex: 0 - }, - - userAgent: 'Firefox' - } - ], - 74000, - true, - null - ] - }, - { - method: 'reportTaskDone', - args: [ - new Date('1970-01-01T00:15:25.000Z'), - 4 - ] - } -]; diff --git a/generators/app/templates/test/test.js b/generators/app/templates/test/test.js index e339201..0dfc251 100644 --- a/generators/app/templates/test/test.js +++ b/generators/app/templates/test/test.js @@ -1,46 +1,7 @@ -var assert = require('assert'); -var normalizeNewline = require('normalize-newline'); -var read = require('read-file-relative').readSync; -var pluginTestingUtils = require('testcafe').pluginTestingUtils; -var pluginFactory = require('../lib'); -var testCalls = require('./data/test-calls'); - -function createReport (withColors) { - var outStream = { - data: '', - - write: function (text) { - this.data += text; - } - }; - - var plugin = pluginTestingUtils.buildReporterPlugin(pluginFactory, outStream); - - plugin.chalk.enabled = !plugin.noColors && withColors; - plugin.symbols = { ok: '✓', err: '✖' }; - - // NOTE: disable errors coloring if we don't have custom - // error decorator. Default error colors may be prone to changing. - if (plugin.chalk.enabled && !pluginFactory().createErrorDecorator) { - var origFormatError = plugin.formatError; - - plugin.formatError = function () { - plugin.chalk.enabled = false; - - var result = origFormatError.apply(plugin, arguments); - - plugin.chalk.enabled = true; - - return result; - }; - } - - testCalls.forEach(function (call) { - plugin[call.method].apply(plugin, call.args); - }); - - return outStream.data; -} +var assert = require('assert'); +var normalizeNewline = require('normalize-newline'); +var read = require('read-file-relative').readSync; +var createReport = require('./utils/create-report'); it('Should produce report with colors', function () { var report = createReport(true); diff --git a/generators/app/templates/test/utils/create-report.js b/generators/app/templates/test/utils/create-report.js new file mode 100644 index 0000000..a7f5998 --- /dev/null +++ b/generators/app/templates/test/utils/create-report.js @@ -0,0 +1,41 @@ +var buildReporterPlugin = require('testcafe').embeddingUtils.buildReporterPlugin; +var pluginFactory = require('../../lib'); +var reporterTestCalls = require('./reporter-test-calls'); + +module.exports = function createReport (withColors) { + var outStream = { + data: '', + + write: function (text) { + this.data += text; + } + }; + + var plugin = buildReporterPlugin(pluginFactory, outStream); + + plugin.chalk.enabled = !plugin.noColors && withColors; + plugin.symbols = { ok: '✓', err: '✖' }; + + // NOTE: disable errors coloring if we don't have custom + // error decorator. Default error colors may be prone to changing. + if (plugin.chalk.enabled && !pluginFactory().createErrorDecorator) { + var origFormatError = plugin.formatError; + + plugin.formatError = function () { + plugin.chalk.enabled = false; + + var result = origFormatError.apply(plugin, arguments); + + plugin.chalk.enabled = true; + + return result; + }; + } + + reporterTestCalls.forEach(function (call) { + plugin[call.method].apply(plugin, call.args); + }); + + // NOTE: mock stack entries + return outStream.data.replace(/\s*?\(.+?:\d+:\d+\)/g, ' (some-file:1:1)'); +}; diff --git a/generators/app/templates/test/utils/reporter-test-calls.js b/generators/app/templates/test/utils/reporter-test-calls.js new file mode 100644 index 0000000..4420069 --- /dev/null +++ b/generators/app/templates/test/utils/reporter-test-calls.js @@ -0,0 +1,144 @@ +var TestRunErrorFormattableAdapter = require('testcafe').embeddingUtils.TestRunErrorFormattableAdapter; +var UncaughtErrorOnPage = require('testcafe').embeddingUtils.testRunErrors.UncaughtErrorOnPage; +var ActionElementNotFoundError = require('testcafe').embeddingUtils.testRunErrors.ActionElementNotFoundError; +var testCallsite = require('./test-callsite'); + + +function makeErrors (errDescrs) { + return errDescrs.map(function (descr) { + return new TestRunErrorFormattableAdapter(descr.err, descr.metaInfo); + }); +} + +module.exports = [ + { + method: 'reportTaskStart', + args: [ + new Date('1970-01-01T00:00:00.000Z'), + [ + 'Chrome 41.0.2227 / Mac OS X 10.10.1', + 'Firefox 47 / Mac OS X 10.10.1' + ], + 6 + ] + }, + { + method: 'reportFixtureStart', + args: [ + 'First fixture', + './fixture1.js' + ] + }, + { + method: 'reportTestDone', + args: [ + 'First test in first fixture', + [], + 74000, + true, + '/screenshots/1445437598847' + ] + }, + { + method: 'reportTestDone', + args: [ + 'Second test in first fixture', + makeErrors([ + { + + err: new UncaughtErrorOnPage('Some error', 'http://example.org'), + + metaInfo: { + userAgent: 'Chrome 41.0.2227 / Mac OS X 10.10.1', + screenshotPath: '/screenshots/1445437598847/errors', + callsite: testCallsite, + testRunState: 'inTest' + } + }, + { + err: new ActionElementNotFoundError(), + + metaInfo: { + userAgent: 'Firefox 47 / Mac OS X 10.10.1', + callsite: testCallsite, + testRunState: 'inTest' + } + } + ]), + 74000, + false, + '/screenshots/1445437598847' + ] + }, + { + method: 'reportTestDone', + args: [ + 'Third test in first fixture', + [], + 74000, + false, + null + ] + }, + { + method: 'reportFixtureStart', + args: [ + 'Second fixture', + './fixture2.js' + ] + }, + { + method: 'reportTestDone', + args: [ + 'First test in second fixture', + [], + 74000, + false, + null + ] + }, + { + method: 'reportTestDone', + args: [ + 'Second test in second fixture', + [], + 74000, + false, + null + ] + }, + { + method: 'reportFixtureStart', + args: [ + 'Third fixture', + './fixture3.js' + ] + }, + { + method: 'reportTestDone', + args: [ + 'First test in third fixture', + makeErrors([ + { + err: new ActionElementNotFoundError(), + + metaInfo: { + userAgent: 'Firefox 47 / Mac OS X 10.10.1', + callsite: testCallsite, + testRunState: 'inBeforeEach' + } + } + ]), + 74000, + true, + null + ] + }, + { + method: 'reportTaskDone', + args: [ + new Date('1970-01-01T00:15:25.000Z'), + 4 + ] + } +]; diff --git a/generators/app/templates/test/utils/test-callsite.js b/generators/app/templates/test/utils/test-callsite.js new file mode 100644 index 0000000..860bbcb --- /dev/null +++ b/generators/app/templates/test/utils/test-callsite.js @@ -0,0 +1,13 @@ +var createCallsiteRecord = require('callsite-record'); + +function someFunc () { + throw new Error('Hey ya!'); +} + +try { + someFunc(); +} +catch (err) { + module.exports = createCallsiteRecord(err); +} + diff --git a/package.json b/package.json index 2a57fef..dc914a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-testcafe-reporter", - "version": "0.0.1", + "version": "1.0.0", "description": "Scaffold out a TestCafe reporter", "homepage": "https://github.com/DevExpress/generator-testcafe-reporter", "author": { @@ -20,7 +20,9 @@ ], "repository": "https://github.com/DevExpress/generator-testcafe-reporter.git", "scripts": { - "test": "gulp test" + "test": "gulp test", + "publish-please": "publish-please", + "prepublish": "publish-please guard" }, "license": "MIT", "dependencies": { @@ -34,6 +36,7 @@ "gulp-mocha": "^2.2.0", "pify": "^2.3.0", "pinkie-promise": "^2.0.0", + "publish-please": "^2.1.4", "yeoman-assert": "^2.1.0" } } diff --git a/test/test.js b/test/test.js index c9326f6..c008d5a 100644 --- a/test/test.js +++ b/test/test.js @@ -38,7 +38,9 @@ it('Should generate expected files', function () { 'test/test.js', 'test/data/report-with-colors.json', 'test/data/report-without-colors', - 'test/data/test-calls.js' + 'test/utils/create-report.js', + 'test/utils/reporter-test-calls.js', + 'test/utils/test-callsite.js' ]); assert.noFileContent('src/index.js', 'createErrorDecorator');