From 69d62c4f22766019c80a7608098444ddbe6b871c Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Sat, 15 Apr 2017 18:51:05 +1000 Subject: [PATCH] refactor: Switch from AVA to Jest for tests. (#122) * tests: Fix `media-query-list-comma-space-before` tests * refactor: Switch from AVA to Jest for tests. --- .../stylelint-config-wordpress/CHANGELOG.md | 1 + .../__tests__/commenting.js | 156 ++++++-- .../__tests__/index.js | 94 ++++- .../__tests__/media-queries-invalid.css | 2 +- .../__tests__/media-queries-valid.css | 2 + .../__tests__/media-queries.js | 376 ++++++++++++++++-- .../__tests__/properties.js | 284 +++++++++++-- .../__tests__/scss.js | 127 ++++-- .../__tests__/selectors-scss.js | 193 +++++++-- .../__tests__/selectors.js | 125 +++++- .../__tests__/structure.js | 315 +++++++++++++-- .../__tests__/values.js | 315 +++++++++++++-- .../__tests__/vendor-prefixes.js | 36 +- packages/stylelint-config-wordpress/index.js | 2 + .../stylelint-config-wordpress/package.json | 23 +- packages/stylelint-config-wordpress/scss.js | 2 + 16 files changed, 1791 insertions(+), 262 deletions(-) diff --git a/packages/stylelint-config-wordpress/CHANGELOG.md b/packages/stylelint-config-wordpress/CHANGELOG.md index 534e2d4cfaf99a..3b1fdb93b13203 100644 --- a/packages/stylelint-config-wordpress/CHANGELOG.md +++ b/packages/stylelint-config-wordpress/CHANGELOG.md @@ -10,6 +10,7 @@ - Deprecated `rule-nested-empty-line-before` and `rule-non-nested-empty-line-before` rules. Use the new `rule-empty-line-before` rule instead. - Deprecated `media-feature-no-missing-punctuation` rule. - Deprecated `selector-no-empty` rule. +- Refactor: Switch from AVA to Jest for tests. # 9.1.1 diff --git a/packages/stylelint-config-wordpress/__tests__/commenting.js b/packages/stylelint-config-wordpress/__tests__/commenting.js index 1a0d9a2534d182..5062d721b7b838 100644 --- a/packages/stylelint-config-wordpress/__tests__/commenting.js +++ b/packages/stylelint-config-wordpress/__tests__/commenting.js @@ -1,34 +1,144 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/commenting-valid.css", "utf-8") const invalidCss = fs.readFileSync("./__tests__/commenting-invalid.css", "utf-8") -test("There are no warnings with commenting CSS", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid commenting css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) + }) + + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid commenting CSS", async t => { - const data = await stylelint.lint({ - code: invalidCss, - config, +describe("flags warnings with invalid commenting css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags three warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(3) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Expected empty line before comment (comment-empty-line-before)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("comment-empty-line-before") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(9) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(1) + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 3, "flags three warnings") - t.is(warnings[0].text, "Expected empty line before comment (comment-empty-line-before)", "correct warning text") - t.is(warnings[1].text, "Expected empty line before comment (comment-empty-line-before)", "correct warning text") - t.is(warnings[2].text, "Expected line length to be no more than 80 characters (max-line-length)", "correct warning text") + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Expected empty line before comment (comment-empty-line-before)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("comment-empty-line-before") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(18) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(1) + )) + }) + + it("correct third warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].text).toBe("Expected line length to be no more than 80 characters (max-line-length)") + )) + }) + + it("correct third warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].rule).toBe("max-line-length") + )) + }) + + it("correct third warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].severity).toBe("error") + )) + }) + + it("correct third warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].line).toBe(24) + )) + }) + + it("correct third warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].column).toBe(131) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/index.js b/packages/stylelint-config-wordpress/__tests__/index.js index ea650f461c5016..870e42401ebc6a 100644 --- a/packages/stylelint-config-wordpress/__tests__/index.js +++ b/packages/stylelint-config-wordpress/__tests__/index.js @@ -1,32 +1,84 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/css-valid.css", "utf-8") const invalidCss = fs.readFileSync("./__tests__/css-invalid.css", "utf-8") -test("no warnings with valid css", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) + }) + + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("a warning with invalid css", async t => { - const data = await stylelint.lint({ - code: invalidCss, - config, +describe("flags warnings with invalid css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags one warning", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(1) + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 1, "flags one warning") - t.is(warnings[0].text, "Expected a leading zero (number-leading-zero)", "correct warning text") + it("correct warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Expected a leading zero (number-leading-zero)") + )) + }) + + it("correct rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("number-leading-zero") + )) + }) + + it("correct severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(2) + )) + }) + + it("correct column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(7) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/media-queries-invalid.css b/packages/stylelint-config-wordpress/__tests__/media-queries-invalid.css index 1d9ab48841023f..4b4655b5f0800a 100644 --- a/packages/stylelint-config-wordpress/__tests__/media-queries-invalid.css +++ b/packages/stylelint-config-wordpress/__tests__/media-queries-invalid.css @@ -33,7 +33,7 @@ /* Your selectors */ } -@media screen and (color), projection and (color) {} +@media screen and (color) , projection and (color) {} @media screen and (color) , projection and (color) {} diff --git a/packages/stylelint-config-wordpress/__tests__/media-queries-valid.css b/packages/stylelint-config-wordpress/__tests__/media-queries-valid.css index 57fa9922816534..d3abffd2e55aa2 100644 --- a/packages/stylelint-config-wordpress/__tests__/media-queries-valid.css +++ b/packages/stylelint-config-wordpress/__tests__/media-queries-valid.css @@ -5,3 +5,5 @@ @media screen and (color), projection and (color) {} + +@media screen and (color), projection and (color) {} diff --git a/packages/stylelint-config-wordpress/__tests__/media-queries.js b/packages/stylelint-config-wordpress/__tests__/media-queries.js index bac58a71e44d7c..361c110c6cc7c0 100644 --- a/packages/stylelint-config-wordpress/__tests__/media-queries.js +++ b/packages/stylelint-config-wordpress/__tests__/media-queries.js @@ -1,40 +1,354 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/media-queries-valid.css", "utf-8") const invalidCss = fs.readFileSync("./__tests__/media-queries-invalid.css", "utf-8") -test("There are no warnings with media queries CSS", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid media queries css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid media queries CSS", async t => { - const data = await stylelint.lint({ - code: invalidCss, - config, - }) - - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 9, "flags ten warnings") - t.is(warnings[0].text, "Unexpected unknown at-rule \"@mdia\" (at-rule-no-unknown)", "correct warning text") - t.is(warnings[1].text, "Expected single space after \":\" (media-feature-colon-space-after)", "correct warning text") - t.is(warnings[2].text, "Expected single space after \":\" (media-feature-colon-space-after)", "correct warning text") - t.is(warnings[3].text, "Unexpected whitespace before \":\" (media-feature-colon-space-before)", "correct warning text") - t.is(warnings[4].text, "Expected single space after range operator (media-feature-range-operator-space-after)", "correct warning text") - t.is(warnings[5].text, "Expected single space after range operator (media-feature-range-operator-space-after)", "correct warning text") - t.is(warnings[6].text, "Expected single space before range operator (media-feature-range-operator-space-before)", "correct warning text") - t.is(warnings[7].text, "Expected single space before range operator (media-feature-range-operator-space-before)", "correct warning text") - t.is(warnings[8].text, "Unexpected whitespace before \",\" (media-query-list-comma-space-before)", "correct warning text") +describe("flags warnings with invalid media queries css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags ten warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(10) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Unexpected unknown at-rule \"@mdia\" (at-rule-no-unknown)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("at-rule-no-unknown") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(31) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(1) + )) + }) + + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Expected single space after \":\" (media-feature-colon-space-after)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("media-feature-colon-space-after") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(1) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(26) + )) + }) + + it("correct third warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].text).toBe("Expected single space after \":\" (media-feature-colon-space-after)") + )) + }) + + it("correct third warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].rule).toBe("media-feature-colon-space-after") + )) + }) + + it("correct third warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].severity).toBe("error") + )) + }) + + it("correct third warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].line).toBe(6) + )) + }) + + it("correct third warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].column).toBe(27) + )) + }) + + it("correct forth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].text).toBe("Unexpected whitespace before \":\" (media-feature-colon-space-before)") + )) + }) + + it("correct forth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].rule).toBe("media-feature-colon-space-before") + )) + }) + + it("correct forth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].severity).toBe("error") + )) + }) + + it("correct forth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].line).toBe(6) + )) + }) + + it("correct forth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].column).toBe(27) + )) + }) + + it("correct fifth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].text).toBe("Expected single space after range operator (media-feature-range-operator-space-after)") + )) + }) + + it("correct fifth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].rule).toBe("media-feature-range-operator-space-after") + )) + }) + + it("correct fifth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].severity).toBe("error") + )) + }) + + it("correct fifth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].line).toBe(16) + )) + }) + + it("correct fifth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].column).toBe(28) + )) + }) + + it("correct sixth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].text).toBe("Expected single space after range operator (media-feature-range-operator-space-after)") + )) + }) + + it("correct sixth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].rule).toBe("media-feature-range-operator-space-after") + )) + }) + + it("correct sixth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].severity).toBe("error") + )) + }) + + it("correct sixth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].line).toBe(21) + )) + }) + + it("correct sixth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].column).toBe(29) + )) + }) + + it("correct seventh warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].text).toBe("Expected single space before range operator (media-feature-range-operator-space-before)") + )) + }) + + it("correct seventh warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].rule).toBe("media-feature-range-operator-space-before") + )) + }) + + it("correct seventh warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].severity).toBe("error") + )) + }) + + it("correct seventh warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].line).toBe(16) + )) + }) + + it("correct seventh warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].column).toBe(25) + )) + }) + + it("correct eighth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].text).toBe("Expected single space before range operator (media-feature-range-operator-space-before)") + )) + }) + + it("correct eighth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].rule).toBe("media-feature-range-operator-space-before") + )) + }) + + it("correct eighth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].severity).toBe("error") + )) + }) + + it("correct eighth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].line).toBe(26) + )) + }) + + it("correct eighth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].column).toBe(25) + )) + }) + + it("correct ninth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[8].text).toBe("Unexpected whitespace before \",\" (media-query-list-comma-space-before)") + )) + }) + + it("correct ninth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[8].rule).toBe("media-query-list-comma-space-before") + )) + }) + + it("correct ninth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[8].severity).toBe("error") + )) + }) + + it("correct ninth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[8].line).toBe(36) + )) + }) + + it("correct ninth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[8].column).toBe(27) + )) + }) + + it("correct tenth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[9].text).toBe("Unexpected whitespace before \",\" (media-query-list-comma-space-before)") + )) + }) + + it("correct tenth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[9].rule).toBe("media-query-list-comma-space-before") + )) + }) + + it("correct tenth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[9].severity).toBe("error") + )) + }) + + it("correct tenth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[9].line).toBe(38) + )) + }) + + it("correct tenth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[9].column).toBe(27) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/properties.js b/packages/stylelint-config-wordpress/__tests__/properties.js index 3f35b49ff36a6b..0cba8e1db778e5 100644 --- a/packages/stylelint-config-wordpress/__tests__/properties.js +++ b/packages/stylelint-config-wordpress/__tests__/properties.js @@ -1,38 +1,264 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/properties-valid.css", "utf-8") const invalidCss = fs.readFileSync("./__tests__/properties-invalid.css", "utf-8") -test("There are no warnings with properties CSS", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid properties css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid properties CSS", async t => { - const data = await stylelint.lint({ - code: invalidCss, - config, - }) - - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 7, "flags seven warnings") - t.is(warnings[0].text, "Expected \"#FFFFFF\" to be \"#ffffff\" (color-hex-case)", "correct warning text") - t.is(warnings[1].text, "Expected \"#FFFFFF\" to be \"#FFF\" (color-hex-length)", "correct warning text") - t.is(warnings[2].text, "Unexpected shorthand \"margin\" after \"margin-left\" (declaration-block-no-shorthand-property-overrides)", "correct warning text") - t.is(warnings[3].text, "Expected single space after \":\" with a single-line declaration (declaration-colon-space-after)", "correct warning text") - t.is(warnings[4].text, "Unexpected unknown property \"argin\" (property-no-unknown)", "correct warning text") - t.is(warnings[5].text, "Expected \"PX\" to be \"px\" (unit-case)", "correct warning text") - t.is(warnings[6].text, "Expected \"BLOCK\" to be \"block\" (value-keyword-case)", "correct warning text") +describe("flags warnings with invalid properties css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags seven warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(7) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Expected \"#FFFFFF\" to be \"#ffffff\" (color-hex-case)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("color-hex-case") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(2) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(13) + )) + }) + + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Expected \"#FFFFFF\" to be \"#FFF\" (color-hex-length)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("color-hex-length") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(2) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(13) + )) + }) + + it("correct third warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].text).toBe("Unexpected shorthand \"margin\" after \"margin-left\" (declaration-block-no-shorthand-property-overrides)") + )) + }) + + it("correct third warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].rule).toBe("declaration-block-no-shorthand-property-overrides") + )) + }) + + it("correct third warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].severity).toBe("error") + )) + }) + + it("correct third warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].line).toBe(5) + )) + }) + + it("correct third warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].column).toBe(2) + )) + }) + + it("correct forth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].text).toBe("Expected single space after \":\" with a single-line declaration (declaration-colon-space-after)") + )) + }) + + it("correct forth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].rule).toBe("declaration-colon-space-after") + )) + }) + + it("correct forth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].severity).toBe("error") + )) + }) + + it("correct forth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].line).toBe(2) + )) + }) + + it("correct forth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].column).toBe(13) + )) + }) + + it("correct fifth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].text).toBe("Unexpected unknown property \"argin\" (property-no-unknown)") + )) + }) + + it("correct fifth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].rule).toBe("property-no-unknown") + )) + }) + + it("correct fifth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].severity).toBe("error") + )) + }) + + it("correct fifth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].line).toBe(6) + )) + }) + + it("correct fifth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].column).toBe(2) + )) + }) + + it("correct sixth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].text).toBe("Expected \"PX\" to be \"px\" (unit-case)") + )) + }) + + it("correct sixth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].rule).toBe("unit-case") + )) + }) + + it("correct sixth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].severity).toBe("error") + )) + }) + + it("correct sixth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].line).toBe(4) + )) + }) + + it("correct sixth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].column).toBe(15) + )) + }) + + it("correct seventh warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].text).toBe("Expected \"BLOCK\" to be \"block\" (value-keyword-case)") + )) + }) + + it("correct seventh warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].rule).toBe("value-keyword-case") + )) + }) + + it("correct seventh warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].severity).toBe("error") + )) + }) + + it("correct seventh warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].line).toBe(3) + )) + }) + + it("correct seventh warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].column).toBe(11) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/scss.js b/packages/stylelint-config-wordpress/__tests__/scss.js index 898688634afa1c..f2c7cd4f0fdab9 100644 --- a/packages/stylelint-config-wordpress/__tests__/scss.js +++ b/packages/stylelint-config-wordpress/__tests__/scss.js @@ -1,35 +1,114 @@ -import fs from "fs" -import config from "../scss.js" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../scss.js") +const stylelint = require("stylelint") const validScss = fs.readFileSync("./__tests__/scss-valid.scss", "utf-8") const invalidScss = fs.readFileSync("./__tests__/scss-invalid.scss", "utf-8") -test("There are no warnings with values SCSS", async t => { - const data = await stylelint.lint({ - code: validScss, - config, - syntax: "scss", +describe("flags no warnings with valid scss", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validScss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid values SCSS", async t => { - const data = await stylelint.lint({ - code: invalidScss, - config, - syntax: "scss", +describe("flags warnings with invalid scss", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidScss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 2, "flags one warning") - t.is(warnings[0].text, "Unexpected unknown at-rule \"@unknown\" (at-rule-no-unknown)", "correct warning text") - t.is(warnings[1].text, "Unexpected unknown at-rule \"@debug\" (at-rule-no-unknown)", "correct warning text") + it("flags two warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(2) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Unexpected unknown at-rule \"@unknown\" (at-rule-no-unknown)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("at-rule-no-unknown") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(1) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(1) + )) + }) + + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Unexpected unknown at-rule \"@debug\" (at-rule-no-unknown)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("at-rule-no-unknown") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(7) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(2) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/selectors-scss.js b/packages/stylelint-config-wordpress/__tests__/selectors-scss.js index d424b49440ba8a..b4ee717a2c4965 100644 --- a/packages/stylelint-config-wordpress/__tests__/selectors-scss.js +++ b/packages/stylelint-config-wordpress/__tests__/selectors-scss.js @@ -1,37 +1,174 @@ -import fs from "fs" -import config from "../scss.js" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../scss.js") +const stylelint = require("stylelint") const validScss = fs.readFileSync("./__tests__/selectors-valid.scss", "utf-8") const invalidScss = fs.readFileSync("./__tests__/selectors-invalid.scss", "utf-8") -test("There are no warnings with values SCSS", async t => { - const data = await stylelint.lint({ - code: validScss, - config, - syntax: "scss", +describe("flags no warnings with valid selectors scss", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validScss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid values SCSS", async t => { - const data = await stylelint.lint({ - code: invalidScss, - config, - syntax: "scss", - }) - - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 4, "flags one warning") - t.is(warnings[0].text, "Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)", "correct warning text") - t.is(warnings[1].text, "Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)", "correct warning text") - t.is(warnings[2].text, "Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)", "correct warning text") - t.is(warnings[3].text, "Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)", "correct warning text") +describe("flags warnings with invalid selectors scss", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidScss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags four warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(4) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("scss/selector-no-redundant-nesting-selector") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(3) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(2) + )) + }) + + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("scss/selector-no-redundant-nesting-selector") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(9) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(2) + )) + }) + + it("correct third warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].text).toBe("Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)") + )) + }) + + it("correct third warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].rule).toBe("scss/selector-no-redundant-nesting-selector") + )) + }) + + it("correct third warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].severity).toBe("error") + )) + }) + + it("correct third warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].line).toBe(14) + )) + }) + + it("correct third warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].column).toBe(2) + )) + }) + + it("correct forth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].text).toBe("Unnecessary nesting selector (&) (scss/selector-no-redundant-nesting-selector)") + )) + }) + + it("correct forth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].rule).toBe("scss/selector-no-redundant-nesting-selector") + )) + }) + + it("correct forth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].severity).toBe("error") + )) + }) + + it("correct forth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].line).toBe(19) + )) + }) + + it("correct forth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].column).toBe(2) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/selectors.js b/packages/stylelint-config-wordpress/__tests__/selectors.js index 6d137fe335ac9d..2ab56e4abfdc06 100644 --- a/packages/stylelint-config-wordpress/__tests__/selectors.js +++ b/packages/stylelint-config-wordpress/__tests__/selectors.js @@ -1,33 +1,114 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/selectors-valid.css", "utf-8") const invalidCss = fs.readFileSync("./__tests__/selectors-invalid.css", "utf-8") -test("There are no warnings with selectors CSS", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid selectors css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid selectors CSS", async t => { - const data = await stylelint.lint({ - code: invalidCss, - config, +describe("flags warnings with invalid selectors css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 2, "flags eight warnings") - t.is(warnings[0].text, "Selector should use lowercase and separate words with hyphens (selector-id-pattern)", "correct warning text") - t.is(warnings[1].text, "Expected double quotes (string-quotes)", "correct warning text") + it("flags two warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(2) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Selector should use lowercase and separate words with hyphens (selector-id-pattern)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("selector-id-pattern") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(21) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(1) + )) + }) + + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Expected double quotes (string-quotes)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("string-quotes") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(17) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(12) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/structure.js b/packages/stylelint-config-wordpress/__tests__/structure.js index 0750cd2dbb0f2a..0967a88454ce7d 100644 --- a/packages/stylelint-config-wordpress/__tests__/structure.js +++ b/packages/stylelint-config-wordpress/__tests__/structure.js @@ -1,39 +1,294 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/structure-valid.css", "utf-8") const invalidCss = fs.readFileSync("./__tests__/structure-invalid.css", "utf-8") -test("There are no warnings with structure CSS", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid structure css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid structure CSS", async t => { - const data = await stylelint.lint({ - code: invalidCss, - config, - }) - - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 8, "flags eight warnings") - t.is(warnings[0].text, "Expected newline before \"}\" (block-closing-brace-newline-before)", "correct warning text") - t.is(warnings[1].text, "Expected newline after \"{\" (block-opening-brace-newline-after)", "correct warning text") - t.is(warnings[2].text, "Expected newline after \";\" (declaration-block-semicolon-newline-after)", "correct warning text") - t.is(warnings[3].text, "Expected indentation of 0 tabs (indentation)", "correct warning text") - t.is(warnings[4].text, "Expected indentation of 1 tab (indentation)", "correct warning text") - t.is(warnings[5].text, "Expected indentation of 1 tab (indentation)", "correct warning text") - t.is(warnings[6].text, "Expected newline after \",\" (selector-list-comma-newline-after)", "correct warning text") - t.is(warnings[7].text, "Expected newline after \",\" (selector-list-comma-newline-after)", "correct warning text") +describe("flags warnings with invalid structure css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags eight warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(8) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Expected newline before \"}\" (block-closing-brace-newline-before)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("block-closing-brace-newline-before") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(7) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(45) + )) + }) + + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Expected newline after \"{\" (block-opening-brace-newline-after)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("block-opening-brace-newline-after") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(7) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(14) + )) + }) + + it("correct third warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].text).toBe("Expected newline after \";\" (declaration-block-semicolon-newline-after)") + )) + }) + + it("correct third warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].rule).toBe("declaration-block-semicolon-newline-after") + )) + }) + + it("correct third warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].severity).toBe("error") + )) + }) + + it("correct third warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].line).toBe(7) + )) + }) + + it("correct third warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].column).toBe(32) + )) + }) + + it("correct forth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].text).toBe("Expected indentation of 0 tabs (indentation)") + )) + }) + + it("correct forth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].rule).toBe("indentation") + )) + }) + + it("correct forth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].severity).toBe("error") + )) + }) + + it("correct forth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].line).toBe(4) + )) + }) + + it("correct forth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].column).toBe(3) + )) + }) + + it("correct fifth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].text).toBe("Expected indentation of 1 tab (indentation)") + )) + }) + + it("correct fifth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].rule).toBe("indentation") + )) + }) + + it("correct fifth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].severity).toBe("error") + )) + }) + + it("correct fifth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].line).toBe(2) + )) + }) + + it("correct fifth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].column).toBe(3) + )) + }) + + it("correct sixth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].text).toBe("Expected indentation of 1 tab (indentation)") + )) + }) + + it("correct sixth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].rule).toBe("indentation") + )) + }) + + it("correct sixth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].severity).toBe("error") + )) + }) + + it("correct sixth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].line).toBe(3) + )) + }) + + it("correct sixth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].column).toBe(3) + )) + }) + + it("correct seventh warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].text).toBe("Expected newline after \",\" (selector-list-comma-newline-after)") + )) + }) + + it("correct seventh warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].rule).toBe("selector-list-comma-newline-after") + )) + }) + + it("correct seventh warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].severity).toBe("error") + )) + }) + + it("correct seventh warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].line).toBe(1) + )) + }) + + it("correct seventh warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].column).toBe(12) + )) + }) + + it("correct eighth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].text).toBe("Expected newline after \",\" (selector-list-comma-newline-after)") + )) + }) + + it("correct eighth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].rule).toBe("selector-list-comma-newline-after") + )) + }) + + it("correct eighth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].severity).toBe("error") + )) + }) + + it("correct eighth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].line).toBe(1) + )) + }) + + it("correct eighth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].column).toBe(25) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/values.js b/packages/stylelint-config-wordpress/__tests__/values.js index cf376b0c53b4f4..2ef4d90b7ce94f 100644 --- a/packages/stylelint-config-wordpress/__tests__/values.js +++ b/packages/stylelint-config-wordpress/__tests__/values.js @@ -1,39 +1,294 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/values-valid.css", "utf-8") const invalidCss = fs.readFileSync("./__tests__/values-invalid.css", "utf-8") -test("There are no warnings with values CSS", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid values css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) -test("There are warnings with invalid values CSS", async t => { - const data = await stylelint.lint({ - code: invalidCss, - config, - }) - - const { errored, results } = data - const { warnings } = results[0] - t.truthy(errored, "errored") - t.is(warnings.length, 8, "flags eight warnings") - t.is(warnings[0].text, "Expected a trailing semicolon (declaration-block-trailing-semicolon)", "correct warning text") - t.is(warnings[1].text, "Expected single space after \":\" with a single-line declaration (declaration-colon-space-after)", "correct warning text") - t.is(warnings[2].text, "Expected quotes around \"Times New Roman\" (font-family-name-quotes)", "correct warning text") - t.is(warnings[3].text, "Expected numeric font-weight notation (font-weight-notation)", "correct warning text") - t.is(warnings[4].text, "Unexpected unit (length-zero-no-unit)", "correct warning text") - t.is(warnings[5].text, "Unexpected unit (length-zero-no-unit)", "correct warning text") - t.is(warnings[6].text, "Unexpected unit (length-zero-no-unit)", "correct warning text") - t.is(warnings[7].text, "Unexpected longhand value '0px 0px 20px 0px' instead of '0px 0px 20px' (shorthand-property-no-redundant-values)", "correct warning text") +describe("flags warnings with invalid values css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags eight warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(8) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Expected a trailing semicolon (declaration-block-trailing-semicolon)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("declaration-block-trailing-semicolon") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(2) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(16) + )) + }) + + it("correct second warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].text).toBe("Expected single space after \":\" with a single-line declaration (declaration-colon-space-after)") + )) + }) + + it("correct second warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].rule).toBe("declaration-colon-space-after") + )) + }) + + it("correct second warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].severity).toBe("error") + )) + }) + + it("correct second warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].line).toBe(2) + )) + }) + + it("correct second warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[1].column).toBe(13) + )) + }) + + it("correct third warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].text).toBe("Expected quotes around \"Times New Roman\" (font-family-name-quotes)") + )) + }) + + it("correct third warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].rule).toBe("font-family-name-quotes") + )) + }) + + it("correct third warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].severity).toBe("error") + )) + }) + + it("correct third warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].line).toBe(10) + )) + }) + + it("correct third warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[2].column).toBe(15) + )) + }) + + it("correct forth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].text).toBe("Expected numeric font-weight notation (font-weight-notation)") + )) + }) + + it("correct forth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].rule).toBe("font-weight-notation") + )) + }) + + it("correct forth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].severity).toBe("error") + )) + }) + + it("correct forth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].line).toBe(11) + )) + }) + + it("correct forth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[3].column).toBe(15) + )) + }) + + it("correct fifth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].text).toBe("Unexpected unit (length-zero-no-unit)") + )) + }) + + it("correct fifth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].rule).toBe("length-zero-no-unit") + )) + }) + + it("correct fifth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].severity).toBe("error") + )) + }) + + it("correct fifth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].line).toBe(6) + )) + }) + + it("correct fifth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[4].column).toBe(11) + )) + }) + + it("correct sixth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].text).toBe("Unexpected unit (length-zero-no-unit)") + )) + }) + + it("correct sixth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].rule).toBe("length-zero-no-unit") + )) + }) + + it("correct sixth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].severity).toBe("error") + )) + }) + + it("correct sixth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].line).toBe(6) + )) + }) + + it("correct sixth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[5].column).toBe(15) + )) + }) + + it("correct seventh warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].text).toBe("Unexpected unit (length-zero-no-unit)") + )) + }) + + it("correct seventh warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].rule).toBe("length-zero-no-unit") + )) + }) + + it("correct seventh warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].severity).toBe("error") + )) + }) + + it("correct seventh warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].line).toBe(6) + )) + }) + + it("correct seventh warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[6].column).toBe(24) + )) + }) + + it("correct eighth warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].text).toBe("Unexpected longhand value '0px 0px 20px 0px' instead of '0px 0px 20px' (shorthand-property-no-redundant-values)") + )) + }) + + it("correct eighth warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].rule).toBe("shorthand-property-no-redundant-values") + )) + }) + + it("correct eighth warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].severity).toBe("error") + )) + }) + + it("correct eighth warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].line).toBe(6) + )) + }) + + it("correct eighth warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[7].column).toBe(2) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/__tests__/vendor-prefixes.js b/packages/stylelint-config-wordpress/__tests__/vendor-prefixes.js index c970383d992d7c..eb4416f14b8850 100644 --- a/packages/stylelint-config-wordpress/__tests__/vendor-prefixes.js +++ b/packages/stylelint-config-wordpress/__tests__/vendor-prefixes.js @@ -1,18 +1,30 @@ -import fs from "fs" -import config from "../" -import stylelint from "stylelint" -import test from "ava" +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") const validCss = fs.readFileSync("./__tests__/vendor-prefixes-valid.css", "utf-8") -test("There are no warnings with vendor prefixes CSS", async t => { - const data = await stylelint.lint({ - code: validCss, - config, +describe("flags no warnings with valid vendor prefixes css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) }) - const { errored, results } = data - const { warnings } = results[0] - t.falsy(errored, "no errored") - t.is(warnings.length, 0, "flags no warnings") + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) + }) + + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/index.js b/packages/stylelint-config-wordpress/index.js index 899f69b9545898..13106e539770b5 100644 --- a/packages/stylelint-config-wordpress/index.js +++ b/packages/stylelint-config-wordpress/index.js @@ -1,3 +1,5 @@ +"use strict" + module.exports = { "rules": { "at-rule-empty-line-before": [ "always", { diff --git a/packages/stylelint-config-wordpress/package.json b/packages/stylelint-config-wordpress/package.json index bf901f6d125391..ea704948335bad 100644 --- a/packages/stylelint-config-wordpress/package.json +++ b/packages/stylelint-config-wordpress/package.json @@ -36,10 +36,10 @@ "node": ">=6.9.1" }, "devDependencies": { - "ava": "^0.19.1", "eslint": "^3.0.0", "eslint-config-stylelint": "^6.0.0", "eslint-plugin-ava": "^4.0.0", + "jest": "^19.0.2", "npm-run-all": "^4.0.0", "npmpub": "^3.0.3", "remark-cli": "^3.0.0", @@ -51,18 +51,13 @@ "stylelint": "^7.5.0" }, "scripts": { - "ava": "ava --verbose \"__tests__/**/*.js\"", "lint:js": "eslint . --ignore-path .gitignore", "lint:md": "remark . --quiet --frail", "lint": "npm-run-all --parallel lint:*", "pretest": "npm run lint", "release": "npmpub --verbose", - "test": "npm run ava" - }, - "babel": { - "presets": [ - "es2015" - ] + "test": "jest", + "watch": "jest --watch" }, "eslintConfig": { "parserOptions": { @@ -72,9 +67,15 @@ "ava" ], "extends": [ - "stylelint", - "plugin:ava/recommended" - ] + "stylelint" + ], + "env": { + "jest": true + } + }, + "jest": { + "testEnvironment": "node", + "verbose": true }, "remarkConfig": { "presets": [ diff --git a/packages/stylelint-config-wordpress/scss.js b/packages/stylelint-config-wordpress/scss.js index 061f4b2d5cd0d2..09a08fd6746eaf 100644 --- a/packages/stylelint-config-wordpress/scss.js +++ b/packages/stylelint-config-wordpress/scss.js @@ -1,3 +1,5 @@ +"use strict" + module.exports = { "extends": [ "./",