From 5525c22310d4cde54f53ae75e68f5321c9a1ef82 Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Fri, 1 Oct 2021 13:29:35 +0100 Subject: [PATCH] Add tests for getVersionAdded in consistency test --- package.json | 2 +- test/linter/index.js | 2 +- test/linter/test-consistency.js | 2 +- test/linter/test-consistency.test.js | 52 ++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/linter/test-consistency.test.js diff --git a/package.json b/package.json index 6b2d17c9be06a7..aab4f71ceb024a 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "scripts": { "confluence": "node ./node_modules/mdn-confluence/main/generate.es6.js --output-dir=. --bcd-module=./index.js", - "mocha": "mocha \"*/**.test.js\"", + "mocha": "mocha \"**/*.test.js\"", "lint": "node test/lint", "fix": "node scripts/fix", "mirror": "node scripts/mirror", diff --git a/test/linter/index.js b/test/linter/index.js index 3f435f5fe846c8..564661d37acf35 100644 --- a/test/linter/index.js +++ b/test/linter/index.js @@ -6,7 +6,7 @@ const testRealValues = require('./test-real-values.js'); const testSchema = require('./test-schema.js'); const testStyle = require('./test-style.js'); const testVersions = require('./test-versions.js'); -const testConsistency = require('./test-consistency.js'); +const { testConsistency } = require('./test-consistency.js'); const testDescriptions = require('./test-descriptions.js'); module.exports = { diff --git a/test/linter/test-consistency.js b/test/linter/test-consistency.js index d029f0bf44af75..b1edcb85525440 100644 --- a/test/linter/test-consistency.js +++ b/test/linter/test-consistency.js @@ -413,4 +413,4 @@ function testConsistency(filename) { return false; } -module.exports = testConsistency; +module.exports = { ConsistencyChecker, testConsistency }; diff --git a/test/linter/test-consistency.test.js b/test/linter/test-consistency.test.js new file mode 100644 index 00000000000000..bb2a63773a3a77 --- /dev/null +++ b/test/linter/test-consistency.test.js @@ -0,0 +1,52 @@ +const assert = require('assert').strict; + +const { ConsistencyChecker } = require('./test-consistency'); + +const check = new ConsistencyChecker(); + +describe('ConsistencyChecker.getVersionAdded()', function () { + it('returns null for non-real values', () => { + assert.equal(check.getVersionAdded({ version_added: null }), null); + }); + + it('returns null for "preview" values', () => { + assert.equal(check.getVersionAdded({ version_added: 'preview' }), null); + }); + + it('returns the value for real and ranged values', () => { + assert.equal(check.getVersionAdded({ version_added: '12' }), '12'); + assert.equal(check.getVersionAdded({ version_added: '≤11' }), '≤11'); + }); + + it('returns the earliest real value for an array support statement', () => { + assert.equal( + check.getVersionAdded([ + { version_added: '≤11' }, + { version_added: '101' }, + ]), + '≤11', + ); + assert.equal( + check.getVersionAdded([ + { version_added: 'preview' }, + { version_added: '≤11', flags: [] }, + ]), + null, + ); + assert.equal( + check.getVersionAdded([ + { version_added: true }, + { version_added: '≤11', flags: [] }, + ]), + null, + ); + + assert.equal( + check.getVersionAdded([ + { version_added: '87' }, + { version_added: true, flags: [] }, + ]), + null, + ); + }); +});