From 28a0cc515c54452ff5d834ce1a8bf8b9bd8cdfa0 Mon Sep 17 00:00:00 2001 From: Kevin Van Lierde Date: Mon, 12 Jun 2023 00:19:03 +0200 Subject: [PATCH] Drops support for Node < 14.14.0 & migrates tests to ESM on src file --- .github/workflows/test.yml | 4 ++-- .prettierignore | 2 +- package.json | 2 +- test/{index.cjs => index.js} | 34 ++++++++++++++++++++-------------- 4 files changed, 24 insertions(+), 18 deletions(-) rename test/{index.cjs => index.js} (92%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b2e066..ea5a557 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: ['ubuntu-latest', 'windows-latest'] - node: ['12.2.0'] + node: ['14.14.0'] name: Testing Node ${{ matrix.node }} on ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -43,7 +43,7 @@ jobs: strategy: matrix: os: ['ubuntu-latest', 'windows-latest'] - node: ['12.2.0', '14.0', '16.0', '18.0'] + node: ['14.14.0', '16.0', '18.0'] name: Testing Node ${{ matrix.node }} on ${{ matrix.os }} steps: - uses: actions/checkout@v3 diff --git a/.prettierignore b/.prettierignore index 3d8000d..3b85841 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,4 @@ test/fixtures/** -.nyc_output/** +coverage/* package-lock.json lib \ No newline at end of file diff --git a/package.json b/package.json index fa8c8e8..7ed1e0c 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ } }, "engines": { - "node": ">=12.2.0" + "node": ">=14.14.0" }, "publishConfig": { "access": "public" diff --git a/test/index.cjs b/test/index.js similarity index 92% rename from test/index.cjs rename to test/index.js index 8cafacd..ae78af8 100644 --- a/test/index.cjs +++ b/test/index.js @@ -1,9 +1,14 @@ /* eslint-env node, mocha */ -const assert = require('assert') -const Metalsmith = require('metalsmith') -const metadata = require('..') -const { name } = require('../package.json') +import assert from 'node:assert' +import { resolve, dirname } from 'node:path' +import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import Metalsmith from 'metalsmith' +import metadata from '../src/index.js' + +const __dirname = dirname(fileURLToPath(import.meta.url)) +const { name } = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8')) describe('@metalsmith/metadata', function () { it('should export a named plugin function matching package.json name', function () { @@ -270,16 +275,17 @@ describe('Error handling', function () { it('should error when TOML is not installed', function (done) { // run this test locally by removing this.skip & running "npm remove toml" this.skip() - const Metalsmith = require('metalsmith') - Metalsmith('test/fixtures/toml') - .env('DEBUG', process.env.DEBUG) - .use(metadata({ file: 'src/data.toml' })) - .build(function (err) { - if (!err) done(new Error('No error was thrown')) - assert(err) - assert(err.message.startsWith('To use toml you must install it first')) - done() - }) + const Metalsmith = import('metalsmith').then(() => { + Metalsmith('test/fixtures/toml') + .env('DEBUG', process.env.DEBUG) + .use(metadata({ file: 'src/data.toml' })) + .build(function (err) { + if (!err) done(new Error('No error was thrown')) + assert(err) + assert(err.message.startsWith('To use toml you must install it first')) + done() + }) + }) }) it('should error for malformed data', function (done) {