Skip to content

Commit 6976e1b

Browse files
committed
Move from fs and rimraf to use toJSON api for tests
1 parent 1ac957e commit 6976e1b

4 files changed

+16
-77
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"@eslint/js": "^9.6.0",
2727
"eslint": "^9.6.0",
2828
"eslint-config-prettier": "^9.1.0",
29-
"prettier": "^3.3.2",
30-
"rimraf": "^6.0.1"
29+
"prettier": "^3.3.2"
3130
}
3231
}

pug/test/test-plugin-data-access.js

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import {strict as assert} from 'node:assert'
2-
import fs from 'node:fs'
1+
import {strictEqual as equal} from 'node:assert'
32
import path from 'node:path'
43
import {
5-
after,
6-
before,
74
describe,
85
describe as context,
96
it
107
} from 'node:test'
118

129
// test subjects
13-
import { rimrafSync } from "rimraf";
1410
import Eleventy from "@11ty/eleventy";
1511

1612

@@ -23,30 +19,13 @@ describe('SCENARIO: Global Data', function() {
2319
}
2420

2521
context('GIVEN some global data', function() {
26-
before(function cleanPreviousTestOutputDirs() {
27-
/* ⚠️ CAUTION:
28-
* Dangerous if you mess with the paths above!
29-
*/
30-
if (output && fs.existsSync(output)) {
31-
rimrafSync(output);
32-
}
33-
})
34-
35-
after(function() {
36-
/* ⚠️ CAUTION:
37-
* Dangerous if you mess with the paths above!
38-
*/
39-
if (output && fs.existsSync(output)) {
40-
rimrafSync(output);
41-
}
42-
})
43-
4422
let eleventyInstance = new Eleventy(input, output, options)
4523

4624
it('The compilation can use the data ', async function() {
47-
await eleventyInstance.executeBuild()
48-
assert(fs.existsSync(output), `output did not exist: ${output}`)
49-
assert(fs.existsSync(path.resolve(output, 'index.html')))
25+
let results = await eleventyInstance.toJSON();
26+
equal(results.length, 1);
27+
equal(results[0].outputPath, "./pug/test-stubs/data-access/_site/index.html");
28+
equal(results[0].url, "/");
5029
})
5130
})
5231
})
+5-25
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import {strict as assert} from 'node:assert'
2-
import fs from 'node:fs'
1+
import {strict as assert, strictEqual as equal} from 'node:assert'
32
import path from 'node:path'
43
import {
5-
after,
6-
before,
74
describe,
85
describe as context,
96
it
107
} from 'node:test'
118

129
// test subjects
13-
import { rimrafSync } from 'rimraf';
1410
import Eleventy from '@11ty/eleventy'
1511

1612

@@ -23,29 +19,13 @@ describe('SCENARIO: Global Data Function', function() {
2319
}
2420

2521
context('GIVEN a function export from global data', function() {
26-
before(function cleanPreviousTestOutputDirs() {
27-
/* ⚠️ CAUTION:
28-
* Dangerous if you mess with the paths above!
29-
*/
30-
if (output && fs.existsSync(output)) {
31-
rimrafSync(output);
32-
}
33-
})
34-
35-
after(function() {
36-
/* ⚠️ CAUTION:
37-
* Dangerous if you mess with the paths above!
38-
*/
39-
if (output && fs.existsSync(output)) {
40-
rimrafSync(output);
41-
}
42-
})
4322
let eleventyInstance = new Eleventy(input, output, options)
4423

4524
it('The compilation can use the data function ', async function() {
46-
await eleventyInstance.executeBuild()
47-
assert(fs.existsSync(output), `output did not exist: ${output}`)
48-
assert(fs.existsSync(path.resolve(output, 'index.html')))
25+
let results = await eleventyInstance.toJSON();
26+
equal(results.length, 1);
27+
equal(results[0].outputPath, "./pug/test-stubs/data-functions/_site/index.html");
28+
equal(results[0].url, "/");
4929
})
5030
})
5131
})

pug/test/test-plugin-minimal-setup.js

+5-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {strict as assert} from 'node:assert'
1+
import {strict as assert, strictEqual as equal} from 'node:assert'
22
import fs from 'node:fs'
3-
import os from 'node:os'
43
import path from 'node:path'
54
import {
65
after,
@@ -9,7 +8,6 @@ import {
98
describe as context,
109
it
1110
} from 'node:test'
12-
import { rimrafSync } from "rimraf";
1311

1412
// test subjects
1513
import plugin from '../index.js'
@@ -47,30 +45,13 @@ describe('SCENARIO: Minimal possible setup', function() {
4745
}
4846

4947
context('WHEN we instantiate Eleventy', function() {
50-
before(function cleanPreviousTestOutputDirs() {
51-
/* ⚠️ CAUTION:
52-
* Dangerous if you mess with the paths above!
53-
*/
54-
if (output && fs.existsSync(output)) {
55-
rimrafSync(output);
56-
}
57-
})
58-
59-
after(function() {
60-
/* ⚠️ CAUTION:
61-
* Dangerous if you mess with the paths above!
62-
*/
63-
if (output && fs.existsSync(output)) {
64-
rimrafSync(output);
65-
}
66-
})
67-
6848
let eleventyInstance = new Eleventy(input, output, options)
6949

7050
it('Can build a Pug file', async function() {
71-
await eleventyInstance.executeBuild()
72-
await assert(fs.existsSync(output), `output did not exist: “${output}”\n`)
73-
assert(fs.existsSync(path.resolve(output, 'index.html')))
51+
let results = await eleventyInstance.toJSON();
52+
equal(results.length, 1);
53+
equal(results[0].outputPath, "./pug/test-stubs/minimal/_site/index.html");
54+
equal(results[0].url, "/");
7455
})
7556

7657
})

0 commit comments

Comments
 (0)