Skip to content

Commit

Permalink
refactor: Switch from AVA to Jest for tests. (#122)
Browse files Browse the repository at this point in the history
* tests: Fix `media-query-list-comma-space-before` tests

* refactor: Switch from AVA to Jest for tests.
  • Loading branch information
ntwb committed May 31, 2020
1 parent 00802b6 commit 69d62c4
Show file tree
Hide file tree
Showing 16 changed files with 1,791 additions and 262 deletions.
1 change: 1 addition & 0 deletions packages/stylelint-config-wordpress/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
156 changes: 133 additions & 23 deletions packages/stylelint-config-wordpress/__tests__/commenting.js
Original file line number Diff line number Diff line change
@@ -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)
))
})
})
94 changes: 73 additions & 21 deletions packages/stylelint-config-wordpress/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -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)
))
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

@media screen and (color),
projection and (color) {}

@media screen and (color), projection and (color) {}
Loading

0 comments on commit 69d62c4

Please sign in to comment.