From cd836ca16fd5e6b0fde0ca626c1cf0343d03ec09 Mon Sep 17 00:00:00 2001 From: Sergey Astapov Date: Fri, 27 May 2022 21:17:09 -0400 Subject: [PATCH] Introduce `eslint-plugin-qunit` per latest addon blueprint --- .eslintrc.js | 5 +++++ package.json | 1 + tests/acceptance/asset-load-test.js | 14 +++++++++----- tests/unit/asset-manifest-test.js | 2 ++ tests/unit/errors/asset-load-test.js | 4 ++-- tests/unit/errors/bundle-load-test.js | 6 +++--- tests/unit/errors/load-test.js | 4 ++-- tests/unit/services/asset-loader-test.js | 14 +++++++------- yarn.lock | 9 +++++++++ 9 files changed, 40 insertions(+), 19 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 442cd2b..1a8154f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -69,5 +69,10 @@ module.exports = { ], }, }, + { + // test files + files: ['tests/**/*-test.{js,ts}'], + extends: ['plugin:qunit/recommended'], + }, ], }; diff --git a/package.json b/package.json index ed372e4..c73b7a3 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "eslint-plugin-ember": "^10.6.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-qunit": "^7.2.0", "loader.js": "^4.7.0", "mocha": "^6.0.2", "npm-run-all": "^4.1.5", diff --git a/tests/acceptance/asset-load-test.js b/tests/acceptance/asset-load-test.js index 43f9706..b0d3e5e 100644 --- a/tests/acceptance/asset-load-test.js +++ b/tests/acceptance/asset-load-test.js @@ -36,21 +36,25 @@ module('Acceptance | asset-load', function (hooks) { const originalColor = originalContainerStyle.color; let containerText = container.innerText; - assert.equal(containerText, '', 'test container is empty before load'); + assert.strictEqual( + containerText, + '', + 'test container is empty before load' + ); await visit('/'); - assert.equal(currentRouteName(), 'index', 'transitioned '); + assert.strictEqual(currentRouteName(), 'index', 'transitioned '); const testScriptText = container.querySelector('h2').innerText; - assert.equal( + assert.strictEqual( testScriptText, 'Test script loaded!', 'test script was executed' ); const routeText = container.querySelector('h1').innerText; - assert.equal(routeText, 'Welcome!', 'route was loaded correctly'); + assert.strictEqual(routeText, 'Welcome!', 'route was loaded correctly'); containerText = container.innerText; assert.ok( @@ -88,7 +92,7 @@ module('Acceptance | asset-load', function (hooks) { await visit('asset-error'); - assert.equal(currentRouteName(), 'asset-error', 'transitioned '); + assert.strictEqual(currentRouteName(), 'asset-error', 'transitioned '); return waitFor(() => !getScript()) .catch((reason) => { diff --git a/tests/unit/asset-manifest-test.js b/tests/unit/asset-manifest-test.js index 385b9d9..d5a56a3 100644 --- a/tests/unit/asset-manifest-test.js +++ b/tests/unit/asset-manifest-test.js @@ -58,6 +58,8 @@ module('Unit | asset-manifest', function (hooks) { }); test('throws an error if unable to load the manifest', function (assert) { + assert.expect(1); + delete requirejs.entries['dummy/config/node-asset-manifest']; const meta = document.querySelector( diff --git a/tests/unit/errors/asset-load-test.js b/tests/unit/errors/asset-load-test.js index d149a71..7d2eecf 100644 --- a/tests/unit/errors/asset-load-test.js +++ b/tests/unit/errors/asset-load-test.js @@ -34,7 +34,7 @@ module('Unit | Error | asset-load', function (hooks) { this.asset, this.originalError ); - assert.equal( + assert.strictEqual( error.toString(), 'AssetLoadError: The js asset with uri "some-js-file.js" failed to load with the error: Error: some error.' ); @@ -46,7 +46,7 @@ module('Unit | Error | asset-load', function (hooks) { this.asset, this.originalError ); - assert.equal( + assert.strictEqual( error.retryLoad(), 'Loaded js asset with uri "some-js-file.js".' ); diff --git a/tests/unit/errors/bundle-load-test.js b/tests/unit/errors/bundle-load-test.js index 2cbe1e2..c5e4d09 100644 --- a/tests/unit/errors/bundle-load-test.js +++ b/tests/unit/errors/bundle-load-test.js @@ -22,7 +22,7 @@ module('Unit | Error | bundle-load', function (hooks) { ); assert.ok(error instanceof Error, 'BundleLoadError inherits Error'); assert.ok(error.stack, 'stack is preserved'); - assert.equal(error.bundleName, this.bundleName, 'bundleName is set'); + assert.strictEqual(error.bundleName, this.bundleName, 'bundleName is set'); assert.strictEqual(error.errors, this.errors, 'errors is set'); }); @@ -32,7 +32,7 @@ module('Unit | Error | bundle-load', function (hooks) { this.bundleName, this.errors ); - assert.equal( + assert.strictEqual( error.toString(), 'BundleLoadError: The bundle "herp-de-derp" failed to load.' ); @@ -44,6 +44,6 @@ module('Unit | Error | bundle-load', function (hooks) { this.bundleName, this.errors ); - assert.equal(error.retryLoad(), 'Loaded the bundle "herp-de-derp".'); + assert.strictEqual(error.retryLoad(), 'Loaded the bundle "herp-de-derp".'); }); }); diff --git a/tests/unit/errors/load-test.js b/tests/unit/errors/load-test.js index 6d31203..ebc6126 100644 --- a/tests/unit/errors/load-test.js +++ b/tests/unit/errors/load-test.js @@ -9,13 +9,13 @@ module('Unit | Error | load', function () { assert.ok(error instanceof Error, 'LoadError inherits Error'); assert.ok(error.stack, 'stack is preserved'); - assert.equal(error.message, message, 'message is set'); + assert.strictEqual(error.message, message, 'message is set'); assert.strictEqual(error.loader, loader, 'loader is set'); }); test('toString() - has correct name and message', function (assert) { const error = new LoadError('herp-de-derp'); - assert.equal(error.toString(), 'LoadError: herp-de-derp'); + assert.strictEqual(error.toString(), 'LoadError: herp-de-derp'); }); test('retryLoad() - throws an error', function (assert) { diff --git a/tests/unit/services/asset-loader-test.js b/tests/unit/services/asset-loader-test.js index f216281..e698896 100644 --- a/tests/unit/services/asset-loader-test.js +++ b/tests/unit/services/asset-loader-test.js @@ -60,7 +60,7 @@ module('Unit | Service | asset-loader', function (hooks) { }); return service.loadBundle('blog').then((bundle) => { - assert.equal(bundle, 'blog'); + assert.strictEqual(bundle, 'blog'); }); }); @@ -97,12 +97,12 @@ module('Unit | Service | asset-loader', function (hooks) { service.defineLoader('fail', () => RSVP.reject('rejected')); return service.loadBundle('blog').then(shouldNotHappen(assert), (error) => { - assert.equal( + assert.strictEqual( error.errors.length, 1, 'has an array of the errors causing the load to fail.' ); - assert.equal( + assert.strictEqual( error.toString(), 'BundleLoadError: The bundle "blog" failed to load.', 'error message contains correct info.' @@ -258,7 +258,7 @@ module('Unit | Service | asset-loader', function (hooks) { service.defineLoader('test', () => RSVP.reject('some error')); return service.loadAsset(asset).then(shouldNotHappen(assert), (error) => { - assert.equal( + assert.strictEqual( error.toString(), 'AssetLoadError: The test asset with uri "someuri" failed to load with the error: some error.' ); @@ -383,7 +383,7 @@ module('Unit | Service | asset-loader', function (hooks) { return service.loadAsset(asset).then(() => { const newNumScripts = document.querySelectorAll('script').length; - assert.equal(newNumScripts, numScripts); + assert.strictEqual(newNumScripts, numScripts); }); }); @@ -395,7 +395,7 @@ module('Unit | Service | asset-loader', function (hooks) { return service.loadAsset(asset).then(() => { const script = document.querySelector('script[src="/unit-test.js"]'); - assert.equal(script.async, false); + assert.false(script.async); }); }); @@ -445,7 +445,7 @@ module('Unit | Service | asset-loader', function (hooks) { return service.loadAsset(asset).then(() => { const newNumLinks = document.querySelectorAll('link').length; - assert.equal(newNumLinks, numLinks); + assert.strictEqual(newNumLinks, numLinks); }); }); diff --git a/yarn.lock b/yarn.lock index b25783c..664967d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7592,6 +7592,14 @@ eslint-plugin-prettier@^4.0.0: dependencies: prettier-linter-helpers "^1.0.0" +eslint-plugin-qunit@^7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-qunit/-/eslint-plugin-qunit-7.2.0.tgz#ad00e0007dc0bbd1d59309cc6388238b6a8784a3" + integrity sha512-ebT6aOpmMj4vchG0hVw9Ukbutk/lgywrc8gc9w9hH2/4WjKqwMlyM7iVwqB7OAXv6gtQMJZuziT0wNjjymAuWA== + dependencies: + eslint-utils "^3.0.0" + requireindex "^1.2.0" + eslint-scope@5.1.1, eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" @@ -13791,6 +13799,7 @@ terser@^5.7.2: "test-generator-plugin@link:./tests/dummy/lib/test-generator-plugin": version "0.0.0" + uid "" testem@^2.14.0: version "2.17.0"