Skip to content

Commit f4a9906

Browse files
authored
Merge pull request #2 from Zearin/refactor/node-test
refactor,test: Rewrite tests using Node builtins
2 parents 47802de + 8a3083c commit f4a9906

File tree

4 files changed

+218
-217
lines changed

4 files changed

+218
-217
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ npm install @11ty/eleventy-utils
2626
npm run test
2727
```
2828

29-
- We use the [ava JavaScript test runner](https://github.com/avajs/ava) ([Assertions documentation](https://github.com/avajs/ava/blob/master/docs/03-assertions.md))
29+
- We use the native NodeJS [test runner](https://nodejs.org/api/test.html#test-runner) and ([assertions](https://nodejs.org/api/assert.html#assert))

package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
"!test/**"
1212
],
1313
"scripts": {
14-
"test": "npx ava --verbose"
14+
"test": "node --test"
1515
},
1616
"license": "MIT",
1717
"engines": {
18-
"node": ">=12"
18+
"node": ">=18"
1919
},
2020
"funding": {
2121
"type": "opencollective",
@@ -37,8 +37,5 @@
3737
"url": "git://github.com/11ty/eleventy-utils.git"
3838
},
3939
"bugs": "https://github.com/11ty/eleventy-utils/issues",
40-
"homepage": "https://github.com/11ty/eleventy-utils/",
41-
"devDependencies": {
42-
"ava": "^6.1.3"
43-
}
40+
"homepage": "https://github.com/11ty/eleventy-utils/"
4441
}

test/IsPlainObjectTest.js

+37-35
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,75 @@
1-
const test = require("ava");
1+
const assert = require("node:assert/strict")
2+
const test = require("node:test");
23
const { isPlainObject } = require("../");
34

5+
46
test("isPlainObject", (t) => {
5-
t.is(isPlainObject(null), false);
6-
t.is(isPlainObject(undefined), false);
7-
t.is(isPlainObject(1), false);
8-
t.is(isPlainObject(true), false);
9-
t.is(isPlainObject(false), false);
10-
t.is(isPlainObject("string"), false);
11-
t.is(isPlainObject([]), false);
12-
t.is(isPlainObject(Symbol("a")), false);
13-
t.is(
7+
assert.equal(isPlainObject(null), false);
8+
assert.equal(isPlainObject(undefined), false);
9+
assert.equal(isPlainObject(1), false);
10+
assert.equal(isPlainObject(true), false);
11+
assert.equal(isPlainObject(false), false);
12+
assert.equal(isPlainObject("string"), false);
13+
assert.equal(isPlainObject([]), false);
14+
assert.equal(isPlainObject(Symbol("a")), false);
15+
assert.equal(
1416
isPlainObject(function () {}),
1517
false
1618
);
1719
});
1820

1921
// https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/test/test.js#L11447
2022
// Notably, did not include the test for DOM Elements.
21-
test("Test from lodash.isPlainObject", (t) => {
22-
t.is(isPlainObject({}), true);
23-
t.is(isPlainObject({ a: 1 }), true);
23+
test("Test from lodash.itPlainObject", (t) => {
24+
assert.equal(isPlainObject({}), true);
25+
assert.equal(isPlainObject({ a: 1 }), true);
2426

2527
function Foo(a) {
2628
this.a = 1;
2729
}
2830

29-
t.is(isPlainObject({ constructor: Foo }), true);
30-
t.is(isPlainObject([1, 2, 3]), false);
31-
t.is(isPlainObject(new Foo(1)), false);
31+
assert.equal(isPlainObject({ constructor: Foo }), true);
32+
assert.equal(isPlainObject([1, 2, 3]), false);
33+
assert.equal(isPlainObject(new Foo(1)), false);
3234
});
3335

34-
test("Test from lodash.isPlainObject: should return `true` for objects with a `[[Prototype]]` of `null`", (t) => {
36+
test("Test from lodash.itPlainObject: should return `true` for objects with a `[[Prototype]]` of `null`", (t) => {
3537
let obj = Object.create(null);
36-
t.is(isPlainObject(obj), true);
38+
assert.equal(isPlainObject(obj), true);
3739

3840
obj.constructor = Object.prototype.constructor;
39-
t.is(isPlainObject(obj), true);
41+
assert.equal(isPlainObject(obj), true);
4042
});
4143

42-
test("Test from lodash.isPlainObject: should return `true` for objects with a `valueOf` property", (t) => {
43-
t.is(isPlainObject({ valueOf: 0 }), true);
44+
test("Test from lodash.itPlainObject: should return `true` for objects with a `valueOf` property", (t) => {
45+
assert.equal(isPlainObject({ valueOf: 0 }), true);
4446
});
4547

46-
test("Test from lodash.isPlainObject: should return `true` for objects with a writable `Symbol.toStringTag` property", (t) => {
48+
test("Test from lodash.itPlainObject: should return `true` for objects with a writable `Symbol.toStringTag` property", (t) => {
4749
let obj = {};
4850
obj[Symbol.toStringTag] = "X";
4951

50-
t.is(isPlainObject(obj), true);
52+
assert.equal(isPlainObject(obj), true);
5153
});
5254

53-
test("Test from lodash.isPlainObject: should return `false` for objects with a custom `[[Prototype]]`", (t) => {
55+
test("Test from lodash.itPlainObject: should return `false` for objects with a custom `[[Prototype]]`", (t) => {
5456
let obj = Object.create({ a: 1 });
55-
t.is(isPlainObject(obj), false);
57+
assert.equal(isPlainObject(obj), false);
5658
});
5759

58-
test("Test from lodash.isPlainObject (modified): should return `false` for non-Object objects", (t) => {
59-
t.is(isPlainObject(arguments), true); // WARNING: lodash was false
60-
t.is(isPlainObject(Error), false);
61-
t.is(isPlainObject(Math), true); // WARNING: lodash was false
60+
test("Test from lodash.itPlainObject (modified): should return `false` for non-Object objects", (t) => {
61+
assert.equal(isPlainObject(arguments), true); // WARNING: lodash was false
62+
assert.equal(isPlainObject(Error), false);
63+
assert.equal(isPlainObject(Math), true); // WARNING: lodash was false
6264
});
6365

64-
test("Test from lodash.isPlainObject: should return `false` for non-objects", (t) => {
65-
t.is(isPlainObject(true), false);
66-
t.is(isPlainObject("a"), false);
67-
t.is(isPlainObject(Symbol("a")), false);
66+
test("Test from lodash.itPlainObject: should return `false` for non-objects", (t) => {
67+
assert.equal(isPlainObject(true), false);
68+
assert.equal(isPlainObject("a"), false);
69+
assert.equal(isPlainObject(Symbol("a")), false);
6870
});
6971

70-
test("Test from lodash.isPlainObject (modified): should return `true` for objects with a read-only `Symbol.toStringTag` property", (t) => {
72+
test("Test from lodash.itPlainObject (modified): should return `true` for objects with a read-only `Symbol.toStringTag` property", (t) => {
7173
var object = {};
7274
Object.defineProperty(object, Symbol.toStringTag, {
7375
configurable: true,
@@ -76,5 +78,5 @@ test("Test from lodash.isPlainObject (modified): should return `true` for object
7678
value: "X",
7779
});
7880

79-
t.is(isPlainObject(object), true); // WARNING: lodash was false
81+
assert.equal(isPlainObject(object), true); // WARNING: lodash was false
8082
});

0 commit comments

Comments
 (0)