From e20b388438605409ad44da8c7780e735c1b20f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Sat, 1 Dec 2018 14:06:03 +0100 Subject: [PATCH 1/2] introducing 'skip visual tests' QUnit option --- addon-test-support/helpers.js | 6 ++++++ addon-test-support/setup.js | 22 ++++++++++++++++++++++ blueprints/ember-visual-test/index.js | 24 +++++++++++++++++++----- tests/test-helper.js | 2 ++ 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 addon-test-support/setup.js diff --git a/addon-test-support/helpers.js b/addon-test-support/helpers.js index 1f0ef31..0db2772 100644 --- a/addon-test-support/helpers.js +++ b/addon-test-support/helpers.js @@ -45,6 +45,12 @@ export async function capture(assert, fileName, { selector = null, fullPage = tr }); } + // if skipvisual QUnit param is true, do nothing + if (queryParams.includes('skipvisual')) { + assert.ok(true, `visual-test: ${fileName} skipped`); + return; + } + // If not in capture mode, make a request to the middleware to capture a screenshot in node let urlQueryParams = [ `testId=${testId}`, diff --git a/addon-test-support/setup.js b/addon-test-support/setup.js new file mode 100644 index 0000000..b1031ea --- /dev/null +++ b/addon-test-support/setup.js @@ -0,0 +1,22 @@ +import QUnit from 'qunit'; + +/** + * Setup QUnit for visual tests + * It adds skip visual tests option to QUnit interface + * This should be called in test-helper.js before QUnit start() method + * + * ``` + * import { start } from 'ember-qunit'; + * import setupVisualTests from 'ember-visual-test/test-support/setup'; + * + * setupVisualTests(); + * start(); + * ``` + */ +export default function() { + QUnit.config.urlConfig.push({ + id: 'skipvisual', + label: 'Skip visual tests', + tooltip: 'Pass all capture calls without performing them' + }); +} diff --git a/blueprints/ember-visual-test/index.js b/blueprints/ember-visual-test/index.js index 7898bd9..1318e4f 100644 --- a/blueprints/ember-visual-test/index.js +++ b/blueprints/ember-visual-test/index.js @@ -6,10 +6,24 @@ module.exports = { }, afterInstall: function() { - return this.insertIntoFile('.gitignore', - `/visual-test-output/tmp/**/*.png -/visual-test-output/diff/**/*.png`).then(function() { - return this.insertIntoFile('.npmignore', `/visual-test-output`); - }.bind(this)) + return this.insertIntoFile( + '.gitignore', + '/visual-test-output/tmp/**/*.png\n/visual-test-output/diff/**/*.png' + ).then(() => this.insertIntoFile( + '.npmignore', + '/visual-test-output' + )).then(() => this.insertIntoFile( + 'tests/test-helper.js', + `import setupVisualTests from 'ember-visual-test/test-support/setup';`, + { + after: `import { start } from 'ember-qunit';\n` + } + )).then(() => this.insertIntoFile( + 'tests/test-helper.js', + 'setupVisualTests();', + { + before: 'start()' + } + )) } }; diff --git a/tests/test-helper.js b/tests/test-helper.js index 0382a84..9932c9e 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -2,7 +2,9 @@ import Application from '../app'; import config from '../config/environment'; import { setApplication } from '@ember/test-helpers'; import { start } from 'ember-qunit'; +import setupVisualTests from 'ember-visual-test/test-support/setup'; setApplication(Application.create(config.APP)); +setupVisualTests(); start(); From aa9e71764502fe3c97384bd45a0c10b2d5298281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Sun, 9 Dec 2018 09:24:20 +0100 Subject: [PATCH 2/2] skip visual tests refactored --- addon-test-support/setup.js | 22 ----------------- blueprints/ember-visual-test/index.js | 24 ++++--------------- index.js | 5 ++++ tests/test-helper.js | 2 -- .../ember-visual-test/qunit-configuration.js | 9 +++++++ 5 files changed, 19 insertions(+), 43 deletions(-) delete mode 100644 addon-test-support/setup.js create mode 100644 vendor/ember-visual-test/qunit-configuration.js diff --git a/addon-test-support/setup.js b/addon-test-support/setup.js deleted file mode 100644 index b1031ea..0000000 --- a/addon-test-support/setup.js +++ /dev/null @@ -1,22 +0,0 @@ -import QUnit from 'qunit'; - -/** - * Setup QUnit for visual tests - * It adds skip visual tests option to QUnit interface - * This should be called in test-helper.js before QUnit start() method - * - * ``` - * import { start } from 'ember-qunit'; - * import setupVisualTests from 'ember-visual-test/test-support/setup'; - * - * setupVisualTests(); - * start(); - * ``` - */ -export default function() { - QUnit.config.urlConfig.push({ - id: 'skipvisual', - label: 'Skip visual tests', - tooltip: 'Pass all capture calls without performing them' - }); -} diff --git a/blueprints/ember-visual-test/index.js b/blueprints/ember-visual-test/index.js index 1318e4f..7898bd9 100644 --- a/blueprints/ember-visual-test/index.js +++ b/blueprints/ember-visual-test/index.js @@ -6,24 +6,10 @@ module.exports = { }, afterInstall: function() { - return this.insertIntoFile( - '.gitignore', - '/visual-test-output/tmp/**/*.png\n/visual-test-output/diff/**/*.png' - ).then(() => this.insertIntoFile( - '.npmignore', - '/visual-test-output' - )).then(() => this.insertIntoFile( - 'tests/test-helper.js', - `import setupVisualTests from 'ember-visual-test/test-support/setup';`, - { - after: `import { start } from 'ember-qunit';\n` - } - )).then(() => this.insertIntoFile( - 'tests/test-helper.js', - 'setupVisualTests();', - { - before: 'start()' - } - )) + return this.insertIntoFile('.gitignore', + `/visual-test-output/tmp/**/*.png +/visual-test-output/diff/**/*.png`).then(function() { + return this.insertIntoFile('.npmignore', `/visual-test-output`); + }.bind(this)) } }; diff --git a/index.js b/index.js index 91431cc..2ebb43e 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,11 @@ module.exports = { this.import('vendor/visual-test.css', { type: 'test' }); + + this.import('vendor/qunit/qunit.js', { type: 'test' }); + this.import('vendor/ember-visual-test/qunit-configuration.js', { + type: 'test' + }); }, async _getBrowser() { diff --git a/tests/test-helper.js b/tests/test-helper.js index 9932c9e..0382a84 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -2,9 +2,7 @@ import Application from '../app'; import config from '../config/environment'; import { setApplication } from '@ember/test-helpers'; import { start } from 'ember-qunit'; -import setupVisualTests from 'ember-visual-test/test-support/setup'; setApplication(Application.create(config.APP)); -setupVisualTests(); start(); diff --git a/vendor/ember-visual-test/qunit-configuration.js b/vendor/ember-visual-test/qunit-configuration.js new file mode 100644 index 0000000..46c5075 --- /dev/null +++ b/vendor/ember-visual-test/qunit-configuration.js @@ -0,0 +1,9 @@ +/* globals QUnit */ + +(function() { + QUnit.config.urlConfig.push({ + id: 'skipvisual', + label: 'Skip visual tests', + tooltip: 'Pass all capture calls without performing them' + }); +})();