Skip to content

Commit

Permalink
fix: drop jest (1/4): remove jest references from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed Apr 22, 2024
1 parent 10c734d commit deb922a
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 56 deletions.
12 changes: 0 additions & 12 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,4 @@ export default [
},
},
},

{
files: ["**/__tests__/**/*.js"],
languageOptions: {
globals: {
expect: "readonly",
test: "readonly",
it: "readonly",
describe: "readonly",
},
},
},
]
27 changes: 25 additions & 2 deletions src/__tests__/TransformableString.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
"use strict"

const TransformableString = require("../TransformableString")

const { it, describe } = require("node:test")
const assert = require("assert")
function expect(actual) {
return {
toBe(expected) {
assert.strictEqual(actual, expected)
},
toEqual(expected) {
assert.deepStrictEqual(actual, expected)
},
toMatch(expected) {
assert.match(actual, expected)
},
toThrow(callback) {
let error = null
try {
callback()
} catch (e) {
error = e
}
assert.notStrictEqual(error, null)
},
}
}

it("should be a function", () => {
expect(typeof TransformableString).toBe("function")
})
Expand Down
61 changes: 58 additions & 3 deletions src/__tests__/extract.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
/*eslint-env es6*/
/*eslint no-sparse-arrays: 0*/

"use strict"
const extract = require("../extract")

const { it, describe, context } = require("node:test")
const assert = require("assert")
function expect(actual) {
return {
toBe(expected) {
assert.strictEqual(actual, expected)
},
toEqual(expected) {
assert.deepStrictEqual(actual, expected)
},
toMatch(expected) {
assert.match(actual, expected)
},
toThrow(callback) {
let error = null
try {
callback()
} catch (e) {
error = e
}
assert.notStrictEqual(error, null)
},
toMatchSnapshot() {
console.log(context.name)
if (typeof actual !== "string") {
throw new Error("toMatchSnapshot() only works with strings")
}
},
}
}

function dedent(str) {
if (str[0] === "\n") str = str.slice(1)

Expand All @@ -27,7 +56,7 @@ function test(params) {
isJavaScriptMIMEType: params.isJavaScriptMIMEType,
ignoreTagsWithoutType: params.ignoreTagsWithoutType,
})
expect(infos.code.map((code) => code.toString())).toMatchSnapshot()
expect(infos.code.map((code) => code.toString())).toEqual(params.expected)
expect(infos.badIndentationLines).toEqual(params.badIndentationLines || [])
}

Expand All @@ -38,6 +67,7 @@ it("extract simple javascript", () => {
<script>var foo = 1;</script>
other
`,
expected: ["var foo = 1;"],
})
})

Expand All @@ -50,6 +80,7 @@ it("extract indented javascript", () => {
</script>
other
`,
expected: ["var foo = 1;\n"],
})
})

Expand All @@ -62,6 +93,7 @@ it("extract javascript with first line next to the script tag", () => {
</script>
other
`,
expected: ["var foo = 1;\nvar baz = 1;\n"],
})
})

Expand All @@ -74,6 +106,7 @@ it("extract javascript with last line next to the script tag", () => {
var baz = 1;</script>
other
`,
expected: ["var foo = 1;\nvar baz = 1;"],
})
})

Expand All @@ -89,6 +122,7 @@ it("extract multiple script tags", () => {
var bar = 1;
</script>
`,
expected: ["var foo = 1;\n", "var bar = 1;\n"],
})
})

Expand All @@ -101,6 +135,7 @@ it("trim last line spaces", () => {
</script>
other
`,
expected: ["var foo = 1;\n"],
})
})

Expand All @@ -114,6 +149,7 @@ it("trim last line spaces ignoring CDATA", () => {
other
`,
xmlMode: true,
expected: ["\nvar foo = 1;\n"],
})
})

Expand All @@ -124,6 +160,7 @@ it("extract script containing 'lower than' characters correctly (#1)", () => {
if (a < b) { doit(); }
</script>
`,
expected: ["if (a < b) { doit(); }\n"],
})
})

Expand All @@ -132,6 +169,7 @@ it("extract empty script tag (#7)", () => {
input: `
<script></script>
`,
expected: [""],
})
})

Expand All @@ -150,6 +188,7 @@ for (const prefix of prefixes) {
<script type="${tag}">var foo = 1;</script>
other
`,
expected: ["var foo = 1;"],
})
})
}
Expand All @@ -165,6 +204,7 @@ it("collects bad indentations", () => {
</script>
`,
badIndentationLines: [3, 4],
expected: ["a;\na;\n a;\n"],
})
})

Expand All @@ -184,6 +224,7 @@ describe("indent option", () => {
spaces: " ",
},
badIndentationLines: [3, 5],
expected: ["\n a;\na;\na;\n"],
})
})

Expand All @@ -203,6 +244,7 @@ describe("indent option", () => {
relative: true,
},
badIndentationLines: [4, 5],
expected: ["a;\n a;\na;\n"],
})
})

Expand All @@ -221,6 +263,7 @@ describe("indent option", () => {
spaces: "\t",
},
badIndentationLines: [3, 5],
expected: ["\n\t\ta;\na;\na;\n"],
})
})

Expand All @@ -240,6 +283,7 @@ describe("indent option", () => {
relative: true,
},
badIndentationLines: [4, 5],
expected: ["a;\n\ta;\na;\n"],
})
})
})
Expand All @@ -249,6 +293,7 @@ it("works with crlf new lines", () => {
input:
"<p>\r\n</p>\r\n<script>\r\n foo;\r\nbar;\r\n baz;\r\n</script>\r\n",
badIndentationLines: [5],
expected: ["foo;\r\nbar;\r\n baz;\r\n"],
})
})

Expand All @@ -263,6 +308,7 @@ it("works with CDATA", () => {
c;
</script>`,
xmlMode: true,
expected: ["a;\n\nb;\n\nc;\n"],
})
})

Expand All @@ -284,6 +330,7 @@ it("handles the isJavaScriptMIMEType option", () => {
isJavaScriptMIMEType(type) {
return type === "foo/bar"
},
expected: ["a\n", "b\n"],
})
})

Expand All @@ -296,32 +343,37 @@ it("keeps empty lines after the last html tags", () => {
`,
expected: ["a\n"],
})
})

it("handles empty input", () => {
test({
input: "",
expected: [],
})
})

it("handles self closing script tags in xhtml mode", () => {
test({
input: "a <script /> b",
xmlMode: true,
expected: [],
})
})

it("skips script with src attributes", () => {
test({
input: '<script src="foo"></script>',
expected: [],
})
})

it("skips script without type attribute", () => {
test({
input: "<script></script>",
ignoreTagsWithoutType: true,
expected: [],
})
})

Expand All @@ -338,6 +390,7 @@ it("extract multiple tags types", () => {
</customscript>
`,
javaScriptTagNames: ["script", "customscript"],
expected: ["var foo = 1;\n", "var bar = 1;\n"],
})
})

Expand All @@ -354,6 +407,7 @@ describe("disable comments", () => {
var bar = 2;
</script>
`,
expected: ["var bar = 2;\n"],
})
})

Expand All @@ -369,6 +423,7 @@ describe("disable comments", () => {
var bar = 2;
</script>
`,
expected: ["var bar = 2;\n"],
})
})
})
25 changes: 24 additions & 1 deletion src/__tests__/getFileMode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
"use strict"
const { test } = require("node:test")
const assert = require("assert")
function expect(actual) {
return {
toBe(expected) {
assert.strictEqual(actual, expected)
},
toEqual(expected) {
assert.deepStrictEqual(actual, expected)
},
toMatch(expected) {
assert.match(actual, expected)
},
toThrow(callback) {
let error = null
try {
callback()
} catch (e) {
error = e
}
assert.notStrictEqual(error, null)
},
}
}

const getFileMode = require("../getFileMode")

Expand Down
Loading

0 comments on commit deb922a

Please sign in to comment.