Skip to content

Commit

Permalink
Move from fs and rimraf to use toJSON api for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 20, 2024
1 parent 1ac957e commit 6976e1b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 77 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@eslint/js": "^9.6.0",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.3.2",
"rimraf": "^6.0.1"
"prettier": "^3.3.2"
}
}
31 changes: 5 additions & 26 deletions pug/test/test-plugin-data-access.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import {strict as assert} from 'node:assert'
import fs from 'node:fs'
import {strictEqual as equal} from 'node:assert'
import path from 'node:path'
import {
after,
before,
describe,
describe as context,
it
} from 'node:test'

// test subjects
import { rimrafSync } from "rimraf";
import Eleventy from "@11ty/eleventy";


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

context('GIVEN some global data', function() {
before(function cleanPreviousTestOutputDirs() {
/* ⚠️ CAUTION:
* Dangerous if you mess with the paths above!
*/
if (output && fs.existsSync(output)) {
rimrafSync(output);
}
})

after(function() {
/* ⚠️ CAUTION:
* Dangerous if you mess with the paths above!
*/
if (output && fs.existsSync(output)) {
rimrafSync(output);
}
})

let eleventyInstance = new Eleventy(input, output, options)

it('The compilation can use the data ', async function() {
await eleventyInstance.executeBuild()
assert(fs.existsSync(output), `output did not exist: ${output}`)
assert(fs.existsSync(path.resolve(output, 'index.html')))
let results = await eleventyInstance.toJSON();
equal(results.length, 1);
equal(results[0].outputPath, "./pug/test-stubs/data-access/_site/index.html");
equal(results[0].url, "/");
})
})
})
30 changes: 5 additions & 25 deletions pug/test/test-plugin-data-functions.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import {strict as assert} from 'node:assert'
import fs from 'node:fs'
import {strict as assert, strictEqual as equal} from 'node:assert'
import path from 'node:path'
import {
after,
before,
describe,
describe as context,
it
} from 'node:test'

// test subjects
import { rimrafSync } from 'rimraf';
import Eleventy from '@11ty/eleventy'


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

context('GIVEN a function export from global data', function() {
before(function cleanPreviousTestOutputDirs() {
/* ⚠️ CAUTION:
* Dangerous if you mess with the paths above!
*/
if (output && fs.existsSync(output)) {
rimrafSync(output);
}
})

after(function() {
/* ⚠️ CAUTION:
* Dangerous if you mess with the paths above!
*/
if (output && fs.existsSync(output)) {
rimrafSync(output);
}
})
let eleventyInstance = new Eleventy(input, output, options)

it('The compilation can use the data function ', async function() {
await eleventyInstance.executeBuild()
assert(fs.existsSync(output), `output did not exist: ${output}`)
assert(fs.existsSync(path.resolve(output, 'index.html')))
let results = await eleventyInstance.toJSON();
equal(results.length, 1);
equal(results[0].outputPath, "./pug/test-stubs/data-functions/_site/index.html");
equal(results[0].url, "/");
})
})
})
29 changes: 5 additions & 24 deletions pug/test/test-plugin-minimal-setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {strict as assert} from 'node:assert'
import {strict as assert, strictEqual as equal} from 'node:assert'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import {
after,
Expand All @@ -9,7 +8,6 @@ import {
describe as context,
it
} from 'node:test'
import { rimrafSync } from "rimraf";

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

context('WHEN we instantiate Eleventy', function() {
before(function cleanPreviousTestOutputDirs() {
/* ⚠️ CAUTION:
* Dangerous if you mess with the paths above!
*/
if (output && fs.existsSync(output)) {
rimrafSync(output);
}
})

after(function() {
/* ⚠️ CAUTION:
* Dangerous if you mess with the paths above!
*/
if (output && fs.existsSync(output)) {
rimrafSync(output);
}
})

let eleventyInstance = new Eleventy(input, output, options)

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

})
Expand Down

0 comments on commit 6976e1b

Please sign in to comment.