From 1b35e88a09a03f613cb13dd6fa8a97007ae24494 Mon Sep 17 00:00:00 2001 From: Josh Tumath Date: Wed, 12 Dec 2018 12:56:06 +0000 Subject: [PATCH 1/7] Run tests using npx --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5e2bb78d..cd1a9438 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "bbc-a11y", - "version": "2.2.6", + "version": "2.3.0", "description": "BBC Accessibility standards checker", "main": "./bin/bbc-a11y.js", "directories": {}, "scripts": { - "test": "./node_modules/.bin/electron-mocha --renderer && ./node_modules/.bin/cucumber-electron && standard", + "test": "npx electron-mocha --renderer && npx cucumber-electron && standard", "standard": "standard", "standard-fix": "standard --fix", "browserify": "browserify ./lib/a11y.js -o ./dist/bundle.js", From 94f90910622238a0e959241e359a60092933d347 Mon Sep 17 00:00:00 2001 From: Josh Tumath Date: Wed, 12 Dec 2018 12:57:06 +0000 Subject: [PATCH 2/7] Allow first heading to be level 2 --- HISTORY.md | 4 ++++ .../standards/mag/structure/02_headings.feature | 16 ++++++++++++++-- .../tests/headingsMustBeInAscendingOrder.js | 16 +++++++++------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index c578e5dc..6baca632 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# v2.3.0 + +- Allow first heading to be level 2 + # v2.2.6 - Disallows nested headings when no content between them, via [#277](https://github.com/bbc/bbc-a11y/pull/277) diff --git a/features/standards/mag/structure/02_headings.feature b/features/standards/mag/structure/02_headings.feature index 188c5f74..1e956f1c 100644 --- a/features/standards/mag/structure/02_headings.feature +++ b/features/standards/mag/structure/02_headings.feature @@ -140,7 +140,19 @@ Feature: Headings Then it passes @html @automated - Scenario: Subheading before the first main heading + Scenario: Level 2 heading before the first main heading + Given a page with the body: + """ +

Heading 2a

+

Heading 3

+

Heading 1

+

Heading 2b

+ """ + When I test the "Structure: Headings: Headings must be in ascending order" standard + Then it passes + + @html @automated + Scenario: Level 3 heading before the first main heading Given a page with the body: """

Ignore me

@@ -150,7 +162,7 @@ Feature: Headings When I test the "Structure: Headings: Headings must be in ascending order" standard Then it passes with the warning: """ - First heading was not a main heading: /html/body/h3 + First heading was not a level 1 or level 2 heading: /html/body/h3 """ @html @automated diff --git a/lib/standards/tests/headingsMustBeInAscendingOrder.js b/lib/standards/tests/headingsMustBeInAscendingOrder.js index 18ab1f52..5d26ecc2 100644 --- a/lib/standards/tests/headingsMustBeInAscendingOrder.js +++ b/lib/standards/tests/headingsMustBeInAscendingOrder.js @@ -3,22 +3,24 @@ module.exports = { type: 'automated', - failsForEach: 'visible heading (

to ) that does follow the next' + + failsForEach: 'visible heading (

to

) that does follow the next' + ' highest-level heading. For example, a

can only come after' + ' a

', test: function ({ $, fail, warn }) { - var headings = $('h1, h2, h3, h4, h5, h6, h7, h8') + var headings = $('h1, h2, h3, h4, h5, h6') var headingLevels = headings.map(function (index, heading) { return { heading: heading, level: parseInt(heading.tagName[1]) } }) + eachCons(headingLevels, 2).forEach(function (pair) { if (pair[1].level > (pair[0].level + 1)) { fail('Headings are not in order:', pair[0].heading, pair[1].heading) } }) - if (headingLevels.length > 0 && headingLevels[0].level > 1) { - warn('First heading was not a main heading:', headingLevels[0].heading) + + if (headingLevels.length > 0 && headingLevels[0].level > 2) { + warn('First heading was not a level 1 or level 2 heading:', headingLevels[0].heading) } } } @@ -32,9 +34,9 @@ function eachCons (a, n) { } function range (a, i, n) { - var r = [] + var array = [] for (var j = 0; j < n; j++) { - r.push(a[i + j]) + array.push(a[i + j]) } - return r + return array } From 30c5e9eb7d171a571f7227490fc0c3ced9afce3a Mon Sep 17 00:00:00 2001 From: Josh Tumath Date: Wed, 12 Dec 2018 17:13:22 +0000 Subject: [PATCH 3/7] Use Node 8 in Travis CI --- .travis.yml | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a38ee790..a9d079c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "7" + - "8" addons: apt: diff --git a/package.json b/package.json index cd1a9438..6e35198c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "author": "BBC", "license": "Apache-2.0", "engines": { - "node": ">=8.x" + "node": ">=8.x", + "npm": ">=5.2" }, "bugs": { "url": "https://github.com/bbc/bbc-a11y/issues" From db1857de5d89779e9499cc40a47771c798f13836 Mon Sep 17 00:00:00 2001 From: Josh Tumath Date: Thu, 13 Dec 2018 10:58:54 +0000 Subject: [PATCH 4/7] Fix CLI acceptance tests --- features/cli/command_line_help.feature | 2 +- features/cli/coverage_reports.feature | 4 ++-- features/cli/display_failing_result.feature | 6 +++--- features/step_definitions/a11y_steps.js | 15 ++++++++++++--- .../two_headings_failures_and_one_warning.html | 2 +- lib/standards/tests/contentMustFollowHeadings.js | 4 ++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/features/cli/command_line_help.feature b/features/cli/command_line_help.feature index cb661e0d..78fa0b6a 100644 --- a/features/cli/command_line_help.feature +++ b/features/cli/command_line_help.feature @@ -2,7 +2,7 @@ Feature: Command Line Help Scenario: Asking the command line tool for help When I run `bbc-a11y --help` - Then it should pass with: + Then it should contain with whitespace removed: """ Usage: bbc-a11y [options] diff --git a/features/cli/coverage_reports.feature b/features/cli/coverage_reports.feature index d930a72d..b1d4a683 100644 --- a/features/cli/coverage_reports.feature +++ b/features/cli/coverage_reports.feature @@ -237,7 +237,7 @@ Feature: Summarise Tests Structure: Headings: Headings must be in ascending order Type: automated - Fails for each visible heading (

to ) that does follow the next highest-level heading. For example, a

can only come after a

+ Fails for each visible heading (

to

) that does follow the next highest-level heading. For example, a

can only come after a

Structure: Headings: Exactly one main heading Type: automated @@ -245,7 +245,7 @@ Feature: Summarise Tests Structure: Headings: Content must follow headings Type: automated - Fails for each heading element (

up to ) that has no text content after it. Text elements may appear as children or descendants of subsequent siblings + Fails for each heading element (

up to

) that has no text content after it. Text elements may appear as children or descendants of subsequent siblings Structure: Containers and landmarks: Containers should be used to describe page structure Type: manual diff --git a/features/cli/display_failing_result.feature b/features/cli/display_failing_result.feature index fb1c943b..35573b08 100644 --- a/features/cli/display_failing_result.feature +++ b/features/cli/display_failing_result.feature @@ -20,7 +20,7 @@ Feature: Display failing result """ ✓ http://localhost:54321/subheading_first.html ⚠ Structure: Headings: Headings must be in ascending order - - First heading was not a main heading: /html/body/h3 + - First heading was not a level 1 or level 2 heading: /html/body/h3 For details on how to fix these errors, please see the following pages: - http://www.bbc.co.uk/guidelines/futuremedia/accessibility/mobile/structure/headings @@ -33,11 +33,11 @@ Feature: Display failing result """ ✗ http://localhost:54321/two_headings_failures_and_one_warning.html ⚠ Structure: Headings: Headings must be in ascending order - - First heading was not a main heading: /html/body/h2 + - First heading was not a level 1 or level 2 heading: /html/body/h4 * Structure: Headings: Exactly one main heading - Found 0 h1 elements. * Structure: Headings: Content must follow headings - - No content follows: /html/body/h2 + - No content follows: /html/body/h4 For details on how to fix these errors, please see the following pages: - http://www.bbc.co.uk/guidelines/futuremedia/accessibility/mobile/structure/headings diff --git a/features/step_definitions/a11y_steps.js b/features/step_definitions/a11y_steps.js index 41ebf1c8..ddbd96d3 100644 --- a/features/step_definitions/a11y_steps.js +++ b/features/step_definitions/a11y_steps.js @@ -176,10 +176,19 @@ Then('it should fail with exactly:', function (expectedOutput) { assert.equal(sanitisedActualOutput, expectedOutput, 'Expected:\n' + expectedOutput.replace(/\n/g, '[\\n]\n') + '\nActual:\n' + sanitisedActualOutput.replace(/\n/g, '[\\n]\n')) }) -Then('it should pass with:', function (string) { +Then('it should pass with:', function (expectedOutput) { var actualOutput = (this.stdout + this.stderr) - if (actualOutput.indexOf(string) === -1) { - throw new Error('Expected:\n' + string + '\nActual:\n' + actualOutput) + if (actualOutput.indexOf(expectedOutput) === -1) { + throw new Error('Expected:\n' + expectedOutput + '\nActual:\n' + actualOutput) + } + assert.equal(this.exitCode, 0) +}) + +Then('it should contain with whitespace removed:', function (expectedOutput) { + var trimmedExpectedOutput = expectedOutput.replace(/\s/g, ''); + var trimmedActualOutput = (this.stdout + this.stderr).replace(/\s/g, '') + if (trimmedActualOutput.indexOf(trimmedExpectedOutput) === -1) { + throw new Error('Expected:\n' + trimmedExpectedOutput + '\nActual:\n' + trimmedActualOutput) } assert.equal(this.exitCode, 0) }) diff --git a/features/support/web_server/two_headings_failures_and_one_warning.html b/features/support/web_server/two_headings_failures_and_one_warning.html index d5160b25..170cd1c3 100644 --- a/features/support/web_server/two_headings_failures_and_one_warning.html +++ b/features/support/web_server/two_headings_failures_and_one_warning.html @@ -7,6 +7,6 @@

-

This is the main heading, but it's not an H1

+

This is the main heading, but it's not an H1

diff --git a/lib/standards/tests/contentMustFollowHeadings.js b/lib/standards/tests/contentMustFollowHeadings.js index c17f7199..ab75516a 100644 --- a/lib/standards/tests/contentMustFollowHeadings.js +++ b/lib/standards/tests/contentMustFollowHeadings.js @@ -1,4 +1,4 @@ -var headingSelector = 'h1, h2, h3, h4, h5, h6, h7, h8' +var headingSelector = 'h1, h2, h3, h4, h5, h6' var iframeSelector = 'iframe:visible' var NODE_IS_FINE = 'node-is-fine' @@ -9,7 +9,7 @@ module.exports = { type: 'automated', - failsForEach: 'heading element (

up to ) that has no text content after it. ' + + failsForEach: 'heading element (

up to

) that has no text content after it. ' + 'Text elements may appear as children or descendants of subsequent siblings', test: function ({ $, fail }) { From f9db4a5da5819434711fedf4729568428518237a Mon Sep 17 00:00:00 2001 From: Josh Tumath Date: Thu, 13 Dec 2018 11:13:24 +0000 Subject: [PATCH 5/7] Remove the forbidden semicolon --- features/step_definitions/a11y_steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/step_definitions/a11y_steps.js b/features/step_definitions/a11y_steps.js index ddbd96d3..4e4b254c 100644 --- a/features/step_definitions/a11y_steps.js +++ b/features/step_definitions/a11y_steps.js @@ -185,7 +185,7 @@ Then('it should pass with:', function (expectedOutput) { }) Then('it should contain with whitespace removed:', function (expectedOutput) { - var trimmedExpectedOutput = expectedOutput.replace(/\s/g, ''); + var trimmedExpectedOutput = expectedOutput.replace(/\s/g, '') var trimmedActualOutput = (this.stdout + this.stderr).replace(/\s/g, '') if (trimmedActualOutput.indexOf(trimmedExpectedOutput) === -1) { throw new Error('Expected:\n' + trimmedExpectedOutput + '\nActual:\n' + trimmedActualOutput) From 523e38e456cbc576a1504c484818c914035eeb8a Mon Sep 17 00:00:00 2001 From: Josh Tumath Date: Thu, 3 Jan 2019 12:00:01 +0000 Subject: [PATCH 6/7] Resolved various review comments --- HISTORY.md | 2 +- features/cli/command_line_help.feature | 2 +- features/standards/mag/structure/02_headings.feature | 2 +- features/step_definitions/a11y_steps.js | 2 +- .../web_server/two_headings_failures_and_one_warning.html | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 6baca632..7a82825b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,6 @@ # v2.3.0 -- Allow first heading to be level 2 +- Main heading (h1) no longer required to be the first heading. # v2.2.6 diff --git a/features/cli/command_line_help.feature b/features/cli/command_line_help.feature index 78fa0b6a..b34abb98 100644 --- a/features/cli/command_line_help.feature +++ b/features/cli/command_line_help.feature @@ -2,7 +2,7 @@ Feature: Command Line Help Scenario: Asking the command line tool for help When I run `bbc-a11y --help` - Then it should contain with whitespace removed: + Then (ignoring whitespace) it should pass with: """ Usage: bbc-a11y [options] diff --git a/features/standards/mag/structure/02_headings.feature b/features/standards/mag/structure/02_headings.feature index 1e956f1c..572cf1e5 100644 --- a/features/standards/mag/structure/02_headings.feature +++ b/features/standards/mag/structure/02_headings.feature @@ -140,7 +140,7 @@ Feature: Headings Then it passes @html @automated - Scenario: Level 2 heading before the first main heading + Scenario: Subheading before the first main heading Given a page with the body: """

Heading 2a

diff --git a/features/step_definitions/a11y_steps.js b/features/step_definitions/a11y_steps.js index 4e4b254c..cf689464 100644 --- a/features/step_definitions/a11y_steps.js +++ b/features/step_definitions/a11y_steps.js @@ -184,7 +184,7 @@ Then('it should pass with:', function (expectedOutput) { assert.equal(this.exitCode, 0) }) -Then('it should contain with whitespace removed:', function (expectedOutput) { +Then(/\(ignoring whitespace\) it should pass with:/, function (expectedOutput) { var trimmedExpectedOutput = expectedOutput.replace(/\s/g, '') var trimmedActualOutput = (this.stdout + this.stderr).replace(/\s/g, '') if (trimmedActualOutput.indexOf(trimmedExpectedOutput) === -1) { diff --git a/features/support/web_server/two_headings_failures_and_one_warning.html b/features/support/web_server/two_headings_failures_and_one_warning.html index 170cd1c3..d05af392 100644 --- a/features/support/web_server/two_headings_failures_and_one_warning.html +++ b/features/support/web_server/two_headings_failures_and_one_warning.html @@ -7,6 +7,6 @@

-

This is the main heading, but it's not an H1

+

This is the main heading, but it's not an H1 or H2

From 773420484e5803bfafab0ced43eef5a0c71d57ac Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Fri, 17 Jul 2020 11:34:49 +0100 Subject: [PATCH 7/7] Revert unrelated changes --- package.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8b6a8c19..6e955838 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "bbc-a11y", - "version": "2.4.2", + "version": "2.4.1", "description": "BBC Accessibility standards checker", "main": "./bin/bbc-a11y.js", "directories": {}, "scripts": { - "test": "npx electron-mocha --renderer && npx cucumber-electron && standard", + "test": "./node_modules/.bin/electron-mocha --renderer && ./node_modules/.bin/cucumber-electron && standard", "standard": "standard", "standard-fix": "standard --fix", "browserify": "browserify ./lib/a11y.js -o ./dist/bundle.js", @@ -23,8 +23,7 @@ "author": "BBC", "license": "Apache-2.0", "engines": { - "node": ">=8.x", - "npm": ">=5.2" + "node": ">=8.x" }, "bugs": { "url": "https://github.com/bbc/bbc-a11y/issues"