diff --git a/package.json b/package.json index 99058bc7..b068bfbb 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,10 @@ "formatters" ], "scripts": { - "test": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 --test-regex=.test.js --test-ignore=node_modules", - "test:integration": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 test/integration/**/*.test.js", - "test:unit": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 test/*.test.js", - "test:tasks": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 test/tasks/*.test.js", + "test": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 --test-regex=.test.mjs --test-ignore=node_modules", + "test:integration": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 test/integration/**/*.test.mjs", + "test:unit": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 test/*.test.mjs", + "test:tasks": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --no-coverage-report --no-cov --timeout 0 test/tasks/*.test.mjs", "test:ci:integration": "npm run test:integration -- --jobs=1", "test:ci:unit": "npm run test:unit -- --jobs=1", "test:ci:tasks": "npm run test:tasks -- --jobs=1", diff --git a/test/alias.test.js b/test/alias.test.mjs similarity index 89% rename from test/alias.test.js rename to test/alias.test.mjs index 195371de..7ccb0847 100644 --- a/test/alias.test.js +++ b/test/alias.test.mjs @@ -1,16 +1,18 @@ -/* eslint-disable no-param-reassign */ - -'use strict'; - -const os = require('os'); -const fs = require('fs').promises; -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const EikService = require('@eik/service'); -const fastify = require('fastify'); -const { sink } = require('@eik/core'); -const { mockLogger } = require('./utils'); -const cli = require('..'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { exec as execCallback } from 'child_process'; +import { join, basename } from 'path'; +import { mockLogger } from './utils.mjs'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const server = fastify({ logger: false }); diff --git a/test/integration/alias.test.js b/test/integration/alias.test.mjs similarity index 91% rename from test/integration/alias.test.js rename to test/integration/alias.test.mjs index 63750187..6b8f7b68 100644 --- a/test/integration/alias.test.js +++ b/test/integration/alias.test.mjs @@ -1,21 +1,21 @@ -'use strict'; - -/* eslint-disable no-param-reassign */ - -const fastify = require('fastify'); -const fs = require('fs').promises; -const os = require('os'); -const cp = require('child_process'); -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const fetch = require('node-fetch'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const cli = require('../..'); +import fastify from 'fastify'; +import { promises as fs } from 'node:fs'; +import os from 'node:os'; +import { exec as execCallback } from 'child_process'; +import { join, basename } from 'node:path'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import cli from '../../classes/index.js'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function exec(cmd) { return new Promise((resolve) => { - cp.exec(cmd, (error, stdout, stderr) => { + execCallback(cmd, (error, stdout, stderr) => { resolve({ error, stdout, stderr }); }); }); diff --git a/test/integration/init.test.js b/test/integration/init.test.mjs similarity index 78% rename from test/integration/init.test.js rename to test/integration/init.test.mjs index 77ba7ef3..4276ae41 100644 --- a/test/integration/init.test.js +++ b/test/integration/init.test.mjs @@ -1,15 +1,18 @@ -'use strict'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { test } from 'tap'; +import { join, basename } from 'path'; +import { readFileSync } from 'fs'; +import { exec as execCallback } from 'child_process'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; -const fs = require('fs').promises; -const os = require('os'); -const { test } = require('tap'); -const { join, basename } = require('path'); -const { readFileSync } = require('fs'); -const cp = require('child_process'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function exec(cmd) { return new Promise((resolve) => { - cp.exec(cmd, (error, stdout, stderr) => { + execCallback(cmd, (error, stdout, stderr) => { resolve({ error, stdout, stderr }); }); }); @@ -22,7 +25,7 @@ test('Initializing a new eik.json file', async (t) => { const publishCmd = `${eik} init --cwd ${folder}`; await exec(publishCmd); - const assets = JSON.parse(readFileSync(join(folder, 'eik.json'))); + const assets = JSON.parse(readFileSync(join(folder, 'eik.json'), { encoding: 'utf8' })); t.equal(assets.name, '', 'eik.json "name" field should be empty'); t.equal( @@ -45,7 +48,7 @@ test('Initializing a new eik.json file passing custom values', async (t) => { --server http://localhost:4001`; await exec(publishCmd.split('\n').join(' ')); - const assets = JSON.parse(readFileSync(join(folder, 'eik.json'))); + const assets = JSON.parse(readFileSync(join(folder, 'eik.json'), { encoding: 'utf8' })); t.equal( assets.name, diff --git a/test/integration/integrity.test.js b/test/integration/integrity.test.mjs similarity index 85% rename from test/integration/integrity.test.js rename to test/integration/integrity.test.mjs index 90b8f09c..dd1fc1e1 100644 --- a/test/integration/integrity.test.js +++ b/test/integration/integrity.test.mjs @@ -1,19 +1,21 @@ -'use strict'; - -/* eslint-disable no-param-reassign */ -const fastify = require('fastify'); -const fs = require('fs').promises; -const os = require('os'); -const cp = require('child_process'); -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const cli = require('../..'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { exec as execCallback } from 'child_process'; +import { join, basename } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import cli from '../../classes/index.js'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function exec(cmd) { return new Promise((resolve) => { - cp.exec(cmd, (error, stdout, stderr) => { + execCallback(cmd, (error, stdout, stderr) => { resolve({ error, stdout, stderr }); }); }); diff --git a/test/integration/login.test.js b/test/integration/login.test.mjs similarity index 71% rename from test/integration/login.test.js rename to test/integration/login.test.mjs index f4d4cde4..b6811c5a 100644 --- a/test/integration/login.test.js +++ b/test/integration/login.test.mjs @@ -1,20 +1,20 @@ -/* eslint-disable no-param-reassign */ - -'use strict'; - -// const util = require('util'); -const fastify = require('fastify'); -const fs = require('fs').promises; -const os = require('os'); -const cp = require('child_process'); -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { exec as execCallback } from 'child_process'; +import { join, basename } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function exec(cmd) { return new Promise((resolve) => { - cp.exec(cmd, (error, stdout, stderr) => { + execCallback(cmd, (error, stdout, stderr) => { resolve({ error, stdout, stderr }); }); }); diff --git a/test/integration/map.test.js b/test/integration/map.test.mjs similarity index 78% rename from test/integration/map.test.js rename to test/integration/map.test.mjs index a27eafcb..64d6c882 100644 --- a/test/integration/map.test.js +++ b/test/integration/map.test.mjs @@ -1,20 +1,22 @@ -'use strict'; +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { exec as execCallback } from 'child_process'; +import { join, basename } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import fetch from 'node-fetch'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import cli from '../../classes/index.js'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; -/* eslint-disable no-param-reassign */ -const fastify = require('fastify'); -const fs = require('fs').promises; -const os = require('os'); -const cp = require('child_process'); -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const fetch = require('node-fetch'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const cli = require('../..'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function exec(cmd) { return new Promise((resolve) => { - cp.exec(cmd, (error, stdout, stderr) => { + execCallback(cmd, (error, stdout, stderr) => { resolve({ error, stdout, stderr }); }); }); diff --git a/test/integration/meta.test.js b/test/integration/meta.test.mjs similarity index 75% rename from test/integration/meta.test.js rename to test/integration/meta.test.mjs index 83899c95..aa1a2f4e 100644 --- a/test/integration/meta.test.js +++ b/test/integration/meta.test.mjs @@ -1,19 +1,21 @@ -'use strict'; +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { exec as execCallback } from 'child_process'; +import { join, basename } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import cli from '../../classes/index.js'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; -/* eslint-disable no-param-reassign */ -const fastify = require('fastify'); -const fs = require('fs').promises; -const os = require('os'); -const cp = require('child_process'); -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const cli = require('../..'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function exec(cmd) { return new Promise((resolve) => { - cp.exec(cmd, (error, stdout, stderr) => { + execCallback(cmd, (error, stdout, stderr) => { resolve({ error, stdout, stderr }); }); }); diff --git a/test/integration/package.test.js b/test/integration/package.test.mjs similarity index 93% rename from test/integration/package.test.js rename to test/integration/package.test.mjs index ec48cd90..7cdbd68c 100644 --- a/test/integration/package.test.js +++ b/test/integration/package.test.mjs @@ -1,20 +1,21 @@ -'use strict'; - -/* eslint-disable no-param-reassign */ -const fastify = require('fastify'); -const fs = require('fs').promises; -const os = require('os'); -const cp = require('child_process'); -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const fetch = require('node-fetch'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const cli = require('../..'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { exec as execCallback } from 'child_process'; +import { join, basename } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import cli from '../../classes/index.js'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function exec(cmd) { return new Promise((resolve) => { - cp.exec(cmd, (error, stdout, stderr) => { + execCallback(cmd, (error, stdout, stderr) => { resolve({ error, stdout, stderr }); }); }); diff --git a/test/integrity.test.js b/test/integrity.test.mjs similarity index 75% rename from test/integrity.test.js rename to test/integrity.test.mjs index 55ce4c0b..6bc58840 100644 --- a/test/integrity.test.js +++ b/test/integrity.test.mjs @@ -1,13 +1,17 @@ -/* eslint-disable no-param-reassign */ +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { mockLogger } from './utils.mjs'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; -'use strict'; - -const { join } = require('path'); -const fastify = require('fastify'); -const { test, beforeEach, afterEach } = require('tap'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const cli = require('..'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const server = fastify({ logger: false }); diff --git a/test/login.test.js b/test/login.test.mjs similarity index 72% rename from test/login.test.js rename to test/login.test.mjs index e62e958d..27364524 100644 --- a/test/login.test.js +++ b/test/login.test.mjs @@ -1,13 +1,17 @@ -/* eslint-disable no-param-reassign */ - -'use strict'; - -const { test, beforeEach, afterEach } = require('tap'); -const fastify = require('fastify'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const { mockLogger } = require('./utils'); -const cli = require('..'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { mockLogger } from './utils.mjs'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const memSink = new sink.MEM(); diff --git a/test/meta.test.js b/test/meta.test.mjs similarity index 76% rename from test/meta.test.js rename to test/meta.test.mjs index 0d4a2c01..8fe80e44 100644 --- a/test/meta.test.js +++ b/test/meta.test.mjs @@ -1,16 +1,17 @@ -/* eslint-disable no-param-reassign */ +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { mockLogger } from './utils.mjs'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; -'use strict'; - -const os = require('os'); -const fs = require('fs').promises; -const { join, basename } = require('path'); -const fastify = require('fastify'); -const { test, beforeEach, afterEach } = require('tap'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const { mockLogger } = require('./utils'); -const cli = require('..'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const server = fastify({ logger: false }); diff --git a/test/publish-files-definitions.test.js b/test/publish-files-definitions.test.mjs similarity index 93% rename from test/publish-files-definitions.test.js rename to test/publish-files-definitions.test.mjs index 877e3dda..9816fc3f 100644 --- a/test/publish-files-definitions.test.js +++ b/test/publish-files-definitions.test.mjs @@ -1,14 +1,17 @@ -/* eslint-disable no-param-reassign */ - -const os = require('os'); -const fs = require('fs').promises; -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const fastify = require('fastify'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const { copySync } = require('fs-extra'); -const cli = require('../classes'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import fsExtra from 'fs-extra'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const config = (files, server, token, cwd) => ({ logger: null, @@ -37,7 +40,7 @@ beforeEach(async (t) => { }); const cwd = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); - copySync(join(__dirname, './fixtures'), join(cwd, 'fixtures')); + fsExtra.copySync(join(__dirname, './fixtures'), join(cwd, 'fixtures')); t.context.server = server; t.context.address = address; diff --git a/test/publish.map.test.js b/test/publish.map.test.mjs similarity index 74% rename from test/publish.map.test.js rename to test/publish.map.test.mjs index 4e515cf2..ab1d71ff 100644 --- a/test/publish.map.test.js +++ b/test/publish.map.test.mjs @@ -1,16 +1,17 @@ -/* eslint-disable no-param-reassign */ +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { mockLogger } from './utils.mjs'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; -'use strict'; - -const os = require('os'); -const fs = require('fs').promises; -const { join, basename } = require('path'); -const fastify = require('fastify'); -const { test, beforeEach, afterEach } = require('tap'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const { mockLogger } = require('./utils'); -const cli = require('..'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const memSink = new sink.MEM(); diff --git a/test/publish.package.test.js b/test/publish.package.test.mjs similarity index 92% rename from test/publish.package.test.js rename to test/publish.package.test.mjs index 1f9cb35e..cabc552b 100644 --- a/test/publish.package.test.js +++ b/test/publish.package.test.mjs @@ -1,16 +1,17 @@ -/* eslint-disable no-param-reassign */ - -'use strict'; - -const os = require('os'); -const fs = require('fs').promises; -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const fastify = require('fastify'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const { mockLogger } = require('./utils'); -const cli = require('..'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { mockLogger } from './utils.mjs'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const memSink = new sink.MEM(); diff --git a/test/tasks/cleanup.test.js b/test/tasks/cleanup.test.mjs similarity index 68% rename from test/tasks/cleanup.test.js rename to test/tasks/cleanup.test.mjs index d0fff319..45fa6b5c 100644 --- a/test/tasks/cleanup.test.js +++ b/test/tasks/cleanup.test.mjs @@ -1,12 +1,13 @@ -/* eslint-disable no-param-reassign */ +import { promises as fs } from 'fs'; +import { join } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import rimraf from 'rimraf'; +import CleanupTask from '../../classes/publish/package/tasks/cleanup.js'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; -'use strict'; - -const fs = require('fs').promises; -const { join } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const rimraf = require('rimraf'); -const CleanupTask = require('../../classes/publish/package/tasks/cleanup'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const path = join(__dirname, '.eik'); diff --git a/test/utils.js b/test/utils.mjs similarity index 85% rename from test/utils.js rename to test/utils.mjs index c752acf6..04dec061 100644 --- a/test/utils.js +++ b/test/utils.mjs @@ -1,7 +1,3 @@ -/* eslint-disable no-underscore-dangle */ - -'use strict'; - const mockLogger = () => { const logs = { fatal: '', @@ -34,4 +30,4 @@ const mockLogger = () => { return { logs, logger }; }; -module.exports.mockLogger = mockLogger; +export { mockLogger }; diff --git a/test/utils.test.js b/test/utils.test.mjs similarity index 87% rename from test/utils.test.js rename to test/utils.test.mjs index 4a147fe1..1fdbfe80 100644 --- a/test/utils.test.js +++ b/test/utils.test.mjs @@ -1,14 +1,17 @@ -'use strict'; - -const os = require('os'); -const { join, basename } = require('path'); -const fs = require('fs'); -const crypto = require('crypto'); -const { test } = require('tap'); -const fastify = require('fastify'); -const j = require('../utils/json'); -const h = require('../utils/hash'); -const f = require('../utils/http'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { test, beforeEach, afterEach } from 'tap'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import crypto from 'crypto'; +import j from '../utils/json/index.js'; +import h from '../utils/hash/index.js'; +import f from '../utils/http/index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); test('calculate file hash', async (t) => { const hash = await h.file(join(__dirname, 'fixtures', 'client.js')); @@ -235,14 +238,14 @@ test('fetch remote hash for a given version', async (t) => { }); test('write JSON file - object - file relative to cwd', async (t) => { - const cwd = await fs.promises.mkdtemp( + const cwd = await fs.mkdtemp( join(os.tmpdir(), basename(__filename)), ); await j.write( { version: '1.0.0', integrity: [] }, { cwd, filename: '.eikrc' }, ); - const eikrc = fs.readFileSync(join(cwd, '.eikrc')); + const eikrc = await fs.readFile(join(cwd, '.eikrc')); const { version, integrity } = JSON.parse(eikrc); t.equal(version, '1.0.0', 'Version should be 1.0.0'); @@ -250,11 +253,11 @@ test('write JSON file - object - file relative to cwd', async (t) => { }); test('write JSON file - object - file absolute path', async (t) => { - const cwd = await fs.promises.mkdtemp( + const cwd = await fs.mkdtemp( join(os.tmpdir(), basename(__filename)), ); await j.write({ prop: 'val' }, { filename: join(cwd, 'test.json') }); - const eikrc = fs.readFileSync(join(cwd, 'test.json')); + const eikrc = await fs.readFile(join(cwd, 'test.json'), { encoding: 'utf8' }); const { prop } = JSON.parse(eikrc); t.equal(prop, 'val', 'Prop should equal val'); @@ -262,48 +265,49 @@ test('write JSON file - object - file absolute path', async (t) => { test('write JSON file - string - file relative path', async (t) => { await j.write({ prop: 'val' }, './test-using-relative.json'); - const eikrc = fs.readFileSync( + const eikrc = await fs.readFile( join(__dirname, '../test-using-relative.json'), + { encoding: 'utf8' }, ); const { prop } = JSON.parse(eikrc); - await fs.unlinkSync(join(__dirname, '../test-using-relative.json')); + await fs.unlink(join(__dirname, '../test-using-relative.json')); t.equal(prop, 'val', 'Prop should equal val'); }); test('write JSON file - string - file absolute path', async (t) => { - const cwd = await fs.promises.mkdtemp( + const cwd = await fs.mkdtemp( join(os.tmpdir(), basename(__filename)), ); await j.write({ prop: 'val' }, join(cwd, 'test3.json')); - const eikrc = fs.readFileSync(join(cwd, 'test3.json')); + const eikrc = await fs.readFile(join(cwd, 'test3.json'), { encoding: 'utf8' }); const { prop } = JSON.parse(eikrc); t.equal(prop, 'val', 'Prop should equal val'); }); test('read JSON file - object - file relative path', async (t) => { - const cwd = await fs.promises.mkdtemp( + const cwd = await fs.mkdtemp( join(os.tmpdir(), basename(__filename)), ); - fs.writeFileSync(join(cwd, 'test3.json'), JSON.stringify({ key: 'val' })); + await fs.writeFile(join(cwd, 'test3.json'), JSON.stringify({ key: 'val' })); const json = await j.read({ cwd, filename: './test3.json' }); t.equal(json.key, 'val', 'Key should equal val'); }); test('read JSON file - object - file absolute path', async (t) => { - const cwd = await fs.promises.mkdtemp( + const cwd = await fs.mkdtemp( join(os.tmpdir(), basename(__filename)), ); - fs.writeFileSync(join(cwd, 'test3.json'), JSON.stringify({ key: 'val' })); + await fs.writeFile(join(cwd, 'test3.json'), JSON.stringify({ key: 'val' })); const json = await j.read({ filename: join(cwd, './test3.json') }); t.equal(json.key, 'val', 'Key should equal val'); }); test('read JSON file - string - file relative path', async (t) => { - fs.writeFileSync( + await fs.writeFile( join(__dirname, '../test-read-json.json'), JSON.stringify({ key: 'val' }), ); @@ -313,10 +317,10 @@ test('read JSON file - string - file relative path', async (t) => { }); test('read JSON file - string - file absolute path', async (t) => { - const cwd = await fs.promises.mkdtemp( + const cwd = await fs.mkdtemp( join(os.tmpdir(), basename(__filename)), ); - fs.writeFileSync( + await fs.writeFile( join(cwd, './test-read-json-2.json'), JSON.stringify({ key: 'val' }), ); diff --git a/test/version.test.js b/test/version.test.mjs similarity index 81% rename from test/version.test.js rename to test/version.test.mjs index 370258fb..dfbff693 100644 --- a/test/version.test.js +++ b/test/version.test.mjs @@ -1,15 +1,17 @@ -/* eslint-disable no-param-reassign */ - -'use strict'; - -const fs = require('fs'); -const os = require('os'); -const { join, basename } = require('path'); -const { test, beforeEach, afterEach } = require('tap'); -const fastify = require('fastify'); -const EikService = require('@eik/service'); -const { sink } = require('@eik/core'); -const cli = require('..'); +import fastify from 'fastify'; +import { promises as fs } from 'fs'; +import os from 'os'; +import { join, basename } from 'path'; +import { mockLogger } from './utils.mjs'; +import { test, beforeEach, afterEach } from 'tap'; +import EikService from '@eik/service'; +import { sink } from '@eik/core'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import cli from '../classes/index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); beforeEach(async (t) => { const memSink = new sink.MEM(); @@ -26,7 +28,7 @@ beforeEach(async (t) => { key: 'change_me', }); - const cwd = await fs.mkdtempSync(join(os.tmpdir(), basename(__filename))); + const cwd = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); t.context.server = server; t.context.address = address;