diff --git a/package.json b/package.json index 855ca102..27dd8a82 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "coverage": "nyc --reporter=lcov --reporter=text npm run test:unit", "lint": "eslint --fix .", "test:live": "cross-env tape 'test/live/**/*-test.js' | tap-arc", - "test:plugins": "cross-env tape 'plugins/**/test/**/*-test.*js' | tap-arc", + "test:plugins": "cross-env tape 'plugins/**/test/**/*-test.mjs' | tap-arc", "test:precommit": "cross-env PRECOMMIT=true npm run gen && npm run lint", - "test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-arc", + "test:unit": "cross-env tape 'test/unit/**/*-test.mjs' | tap-arc", "test": "npm run lint && npm run gen && npm run test:plugins && npm run coverage" }, "simple-git-hooks": { diff --git a/plugins/cloudfront/test/xml-test.mjs b/plugins/cloudfront/test/xml-test.mjs index a0f3cb89..45a9d98b 100644 --- a/plugins/cloudfront/test/xml-test.mjs +++ b/plugins/cloudfront/test/xml-test.mjs @@ -1,5 +1,5 @@ -import url from 'url' -import { join } from 'path' +import url from 'node:url' +import { join } from 'node:path' import test from 'tape' import { readFile } from 'node:fs/promises' import { parseXML, buildXML } from '../../../src/lib/index.js' diff --git a/plugins/s3/test/s3-test.mjs b/plugins/s3/test/s3-test.mjs index 19b85885..c7e3ec63 100644 --- a/plugins/s3/test/s3-test.mjs +++ b/plugins/s3/test/s3-test.mjs @@ -1,14 +1,11 @@ -let { join } = require('node:path') -let cwd = process.cwd() -let sut = join(cwd, 'src', 'index.js') -let client = require(sut) -let test = require('tape') -let mockTmp = require('mock-tmp') -let { parseXML } = require('../../../src/lib') -let { defaults } = require('../../../test/lib') +import { join } from 'node:path' +import test from 'tape' +import mockTmp from 'mock-tmp' +import { parseXML } from '../../../src/lib/index.js' +import { defaults } from '../../../test/lib/index.mjs' let { config } = defaults -let aws, tmp +let aws, client, tmp let bucketName = 'bucket1' let objectNames = [ 'object1.txt', 'object2.json' ] let objectContents = [ 'Hello, World!', JSON.stringify({ welcome: 'aws-lite' }) ] @@ -24,6 +21,9 @@ let okXml = { test('Set up env', async t => { t.plan(2) + let cwd = process.cwd() + let sut = 'file://' + join(cwd, 'src', 'index.js') + client = (await import(sut)).default client.testing.enable({ usePluginResponseMethod: true }) aws = await client({ ...config, plugins: [ import('@aws-lite/s3') ] }) t.ok(aws, 'Client ready') diff --git a/scripts/generate-plugins/_types.mjs b/scripts/generate-plugins/_types.mjs index ccd6f2d4..af69db84 100644 --- a/scripts/generate-plugins/_types.mjs +++ b/scripts/generate-plugins/_types.mjs @@ -114,7 +114,7 @@ export default async function main ({ service, property, display }) { const packageName = `@aws-lite/${service}` const pluginTypesDir = join(CWD, 'plugins', service, 'types') - const { methods } = (await import(join(CWD, 'plugins', service, 'src', 'index.mjs'))).default + const { methods } = (await import('file://' + join(CWD, 'plugins', service, 'src', 'index.mjs'))).default if (!existsSync(pluginTypesDir)) { // new plugin types package - this only happens once diff --git a/test/lib/index.mjs b/test/lib/index.mjs index da613109..57733821 100644 --- a/test/lib/index.mjs +++ b/test/lib/index.mjs @@ -1,5 +1,6 @@ -let os = require('node:os') -const http = require('node:http') +import os from 'node:os' +import http from 'node:http' +import process from 'node:process' // Test defaults const accessKeyId = 'foo' @@ -35,7 +36,7 @@ let server = { const reqType = req.headers?.['content-type'] /**/ if (reqType?.includes('json')) body = JSON.parse(data) else if (reqType?.includes('xml')) body = data.toString() - else body = Buffer.concat(data) + else body = data.join('') } serverData.request = { url: req.url, @@ -126,7 +127,7 @@ function resetAWSEnvVars () { delete process.env.AWS_SHARED_CREDENTIALS_FILE } -module.exports = { +export { basicRequestChecks, copy, defaults, diff --git a/test/unit/plugins/plugins-test.mjs b/test/unit/plugins/plugins-test.mjs index d5508020..4b4b6817 100644 --- a/test/unit/plugins/plugins-test.mjs +++ b/test/unit/plugins/plugins-test.mjs @@ -1,12 +1,14 @@ -let { join } = require('node:path') -let test = require('tape') +import { join } from 'node:path' +import process from 'node:process' +import test from 'tape' + let cwd = process.cwd() let validTypes = [ 'array', 'boolean', 'buffer', 'number', 'object', 'string' ] let plugins test('Set up env', async t => { t.plan(1) - plugins = (await import('../../../plugins.mjs')).default + plugins = (await import('file://' + join(cwd, 'plugins.mjs'))).default t.ok(plugins.length, `Loaded ${plugins.length} \`@aws-lite/*\` plugins`) }) @@ -15,7 +17,7 @@ test('Check plugins for docs + validation', async t => { for (let { service } of plugins) { let prefix = process.platform.startsWith('win') ? 'file://' : '' let path = service => prefix + join(cwd, 'plugins', service, 'src', 'index.mjs') - let plugin = (await import(path(service))).default + let plugin = (await import('file://' + path(service))).default t.comment(`@aws-lite/${service}`) // Traverse methods diff --git a/test/unit/src/config/get-creds-test.mjs b/test/unit/src/config/get-creds-test.mjs index e55b58f8..2eff19f1 100644 --- a/test/unit/src/config/get-creds-test.mjs +++ b/test/unit/src/config/get-creds-test.mjs @@ -1,12 +1,12 @@ -let { readFileSync } = require('node:fs') -let { join } = require('node:path') -let test = require('tape') -let mockTmp = require('mock-tmp') -let { defaults, overrideHomedir, resetAWSEnvVars } = require('../../../lib') +import { readFileSync } from 'node:fs' +import { join } from 'node:path' +import process from 'node:process' +import test from 'tape' +import mockTmp from 'mock-tmp' +import { defaults, overrideHomedir, resetAWSEnvVars } from '../../../lib/index.mjs' + +let getCreds let cwd = process.cwd() -let sut = join(cwd, 'src', 'config', 'get-creds.js') -let getCreds = require(sut) - let { profile } = defaults let mock = join(cwd, 'test', 'mock') let ok = 'foo' @@ -14,8 +14,10 @@ let nope = 'bar' let num = 1 let credentialsMock = join(mock, '.aws', 'credentials') -test('Set up env', t => { +test('Set up env', async t => { t.plan(1) + let sut = 'file://' + join(cwd, 'src', 'config', 'get-creds.js') + getCreds = (await import(sut)).default t.ok(getCreds, 'getCreds module is present') }) diff --git a/test/unit/src/config/get-endpoint-test.mjs b/test/unit/src/config/get-endpoint-test.mjs index c0890c31..e12fad57 100644 --- a/test/unit/src/config/get-endpoint-test.mjs +++ b/test/unit/src/config/get-endpoint-test.mjs @@ -1,12 +1,12 @@ -let { readFileSync } = require('node:fs') -let { join } = require('node:path') -let test = require('tape') -let mockTmp = require('mock-tmp') -let { defaults, overrideHomedir, resetAWSEnvVars } = require('../../../lib') +import { readFileSync } from 'node:fs' +import { join } from 'node:path' +import test from 'tape' +import process from 'node:process' +import mockTmp from 'mock-tmp' +import { defaults, overrideHomedir, resetAWSEnvVars } from '../../../lib/index.mjs' + +let getEndpoint let cwd = process.cwd() -let sut = join(cwd, 'src', 'config', 'get-endpoint.js') -let getEndpoint = require(sut) - let { profile } = defaults let mock = join(cwd, 'test', 'mock') let configMock = join(mock, '.aws', 'config') @@ -18,8 +18,10 @@ let https = 'https:', http = 'http:' let pathPrefix = '/foo-bar' let protocol = https // https is the sensible default! -test('Set up env', t => { +test('Set up env', async t => { t.plan(1) + let sut = 'file://' + join(cwd, 'src', 'config', 'get-endpoint.js') + getEndpoint = (await import(sut)).default t.ok(getEndpoint, 'getEndpoint module is present') }) diff --git a/test/unit/src/config/get-plugins-test.mjs b/test/unit/src/config/get-plugins-test.mjs index ec9ef131..fcc69c00 100644 --- a/test/unit/src/config/get-plugins-test.mjs +++ b/test/unit/src/config/get-plugins-test.mjs @@ -1,16 +1,20 @@ -let { readFileSync } = require('node:fs') -let { join } = require('node:path') -let test = require('tape') -let mockTmp = require('mock-tmp') +import { readFileSync } from 'node:fs' +import module from 'node:module' +import { join } from 'node:path' +import process from 'node:process' +import mockTmp from 'mock-tmp' +import test from 'tape' + +let getPlugins let cwd = process.cwd() -let sut = join(cwd, 'src', 'config', 'get-plugins.js') -let getPlugins = require(sut) - +let require = module.createRequire(import.meta.url) let mock = join(cwd, 'test', 'mock') let pluginDir = join(mock, 'plugins') -test('Set up env', t => { +test('Set up env', async t => { t.plan(1) + let sut = 'file://' + join(cwd, 'src', 'config', 'get-plugins.js') + getPlugins = (await import(sut)).default t.ok(getPlugins, 'getPlugins module is present') }) @@ -20,21 +24,14 @@ test('Just return an empty array ', async t => { }) test('Load plugins array', async t => { - t.plan(2) + t.plan(4) let plugins - // Node.js 14.x + npm 6 does funky things with npm link-ed (symlinked) modules - // That's cool, we can confidently skip this test for now, the related code path provably works! - if (!process.versions.node.startsWith('14')) { - t.plan(4) - // eslint-disable-next-line - plugins = await getPlugins({ plugins: [ import('@aws-lite/dynamodb') ] }) - t.equal(plugins[0].service, 'dynamodb', 'Client explicitly loaded ESM plugin with unresolved import') - - // eslint-disable-next-line - plugins = await getPlugins({ plugins: [ await import('@aws-lite/lambda') ] }) - t.equal(plugins[0].service, 'lambda', 'Client explicitly loaded ESM plugin with resolved import') - } + plugins = await getPlugins({ plugins: [ import('@aws-lite/dynamodb') ] }) + t.equal(plugins[0].service, 'dynamodb', 'Client explicitly loaded ESM plugin with unresolved import') + + plugins = await getPlugins({ plugins: [ await import('@aws-lite/lambda') ] }) + t.equal(plugins[0].service, 'lambda', 'Client explicitly loaded ESM plugin with resolved import') let cjsPluginPath = join(pluginDir, 'cjs') plugins = await getPlugins({ plugins: [ require(cjsPluginPath) ] }) diff --git a/test/unit/src/config/get-region-test.mjs b/test/unit/src/config/get-region-test.mjs index a40a7796..95c7eae2 100644 --- a/test/unit/src/config/get-region-test.mjs +++ b/test/unit/src/config/get-region-test.mjs @@ -1,12 +1,12 @@ -let { readFileSync } = require('node:fs') -let { join } = require('node:path') -let test = require('tape') -let mockTmp = require('mock-tmp') -let { defaults, overrideHomedir, resetAWSEnvVars } = require('../../../lib') +import { readFileSync } from 'node:fs' +import { join } from 'node:path' +import test from 'tape' +import process from 'node:process' +import mockTmp from 'mock-tmp' +import { defaults, overrideHomedir, resetAWSEnvVars } from '../../../lib/index.mjs' + +let getRegion let cwd = process.cwd() -let sut = join(cwd, 'src', 'config', 'get-region.js') -let getRegion = require(sut) - let { profile } = defaults let mock = join(cwd, 'test', 'mock') let east1 = 'us-east-1' @@ -15,8 +15,10 @@ let west2 = 'us-west-2' let num = 1 let configMock = join(mock, '.aws', 'config') -test('Set up env', t => { +test('Set up env', async t => { t.plan(1) + let sut = 'file://' + join(cwd, 'src', 'config', 'get-region.js') + getRegion = (await import(sut)).default t.ok(getRegion, 'getRegion module is present') }) diff --git a/test/unit/src/index-client-test.mjs b/test/unit/src/index-client-test.mjs index 54890e50..e15253fb 100644 --- a/test/unit/src/index-client-test.mjs +++ b/test/unit/src/index-client-test.mjs @@ -1,15 +1,17 @@ -let { join } = require('node:path') -let { Readable } = require('node:stream') -let qs = require('node:querystring') -let test = require('tape') -let { basicRequestChecks, copy, defaults, resetServer: reset, server } = require('../../lib') -let cwd = process.cwd() -let sut = join(cwd, 'src', 'index.js') -let client = require(sut) - +import { join } from 'node:path' +import { Readable } from 'node:stream' +import process from 'node:process' +import qs from 'node:querystring' +import { Buffer } from 'node:buffer' +import test from 'tape' +import { basicRequestChecks, copy, defaults, resetServer as reset, server } from '../../lib/index.mjs' +import url from 'node:url' + +let client let { badPort, config, host, protocol, service, path, port } = defaults let jsonHeaders = { 'content-type': 'application/json' } let xmlHeaders = { 'content-type': 'application/xml' } +let __filename = url.fileURLToPath(import.meta.url) /** * Reminder! @@ -18,6 +20,9 @@ let xmlHeaders = { 'content-type': 'application/xml' } test('Set up env', async t => { t.plan(2) + let cwd = process.cwd() + let sut = 'file://' + join(cwd, 'src', 'index.js') + client = (await import(sut)).default t.ok(client, 'aws-lite client is present') let started = await server.start() t.ok(started, 'Started server') diff --git a/test/unit/src/index-config-test.mjs b/test/unit/src/index-config-test.mjs index 0a26e139..a5a0f352 100644 --- a/test/unit/src/index-config-test.mjs +++ b/test/unit/src/index-config-test.mjs @@ -1,18 +1,22 @@ -let { join } = require('node:path') -let mockTmp = require('mock-tmp') -let test = require('tape') -let { basicRequestChecks, defaults, resetAWSEnvVars: reset, server } = require('../../lib') +import module from 'node:module' +import { join } from 'node:path' +import process from 'node:process' +import mockTmp from 'mock-tmp' +import test from 'tape' +import { basicRequestChecks, defaults, resetAWSEnvVars as reset, server } from '../../lib/index.mjs' + +let client let cwd = process.cwd() -let sut = join(cwd, 'src', 'index.js') -let client = require(sut) - let { accessKeyId, badPort, config, host, path, port, protocol, region, secretAccessKey, service } = defaults let profile1 = 'profile_1' let mock = join(cwd, 'test', 'mock') let pluginDir = join(mock, 'plugins') +let require = module.createRequire(import.meta.url) test('Set up env', async t => { t.plan(1) + let sut = 'file://' + join(cwd, 'src', 'index.js') + client = (await import(sut)).default t.ok(client, 'aws-lite client is present') }) @@ -53,22 +57,15 @@ test('Configuration - basic config', async t => { }) test('Configuration - plugin loading', async t => { - t.plan(6) + t.plan(9) let aws, tmp let minConfig = { accessKeyId, secretAccessKey, region } - // Node.js 14.x + npm 6 does funky things with npm link-ed (symlinked) modules - // That's cool, we can confidently skip this test for now, the related code path provably works! - if (!process.versions.node.startsWith('14')) { - t.plan(9) - // eslint-disable-next-line - aws = await client({ ...minConfig, plugins: [ import('@aws-lite/ssm') ] }) - t.ok(aws.ssm, 'Client explicitly loaded ESM plugin with unresolved import') - - // eslint-disable-next-line - aws = await client({ ...minConfig, plugins: [ await import('@aws-lite/sqs') ] }) - t.ok(aws.sqs, 'Client explicitly loaded ESM plugin with resolved import') - } + aws = await client({ ...minConfig, plugins: [ import('@aws-lite/ssm') ] }) + t.ok(aws.ssm, 'Client explicitly loaded ESM plugin with unresolved import') + + aws = await client({ ...minConfig, plugins: [ await import('@aws-lite/sqs') ] }) + t.ok(aws.sqs, 'Client explicitly loaded ESM plugin with resolved import') let cjsPluginPath = join(pluginDir, 'cjs') aws = await client({ ...minConfig, plugins: [ require(cjsPluginPath) ] }) @@ -78,11 +75,8 @@ test('Configuration - plugin loading', async t => { aws = await client({ ...minConfig, plugins: [ plugin ] }) t.ok(aws.lambda, 'Client explicitly loaded CJS plugin object') - // See above - if (!process.versions.node.startsWith('14')) { - aws = await client({ ...minConfig, autoloadPlugins: true }) - t.ok(aws.dynamodb, 'Client auto-loaded @aws-lite/dynamodb') - } + aws = await client({ ...minConfig, autoloadPlugins: true }) + t.ok(aws.dynamodb, 'Client auto-loaded @aws-lite/dynamodb') aws = await client({ ...minConfig }) t.notOk(aws.dynamodb, 'Client did not auto-load @aws-lite/dynamodb') diff --git a/test/unit/src/index-plugins-test.mjs b/test/unit/src/index-plugins-test.mjs index e20e0139..5e6f1ce3 100644 --- a/test/unit/src/index-plugins-test.mjs +++ b/test/unit/src/index-plugins-test.mjs @@ -1,18 +1,24 @@ -let { join } = require('node:path') -let test = require('tape') -let { basicRequestChecks, defaults, resetServer: reset, server } = require('../../lib') +import module from 'node:module' +import { join } from 'node:path' +import process from 'node:process' +import url from 'node:url' +import test from 'tape' +import { basicRequestChecks, defaults, resetServer as reset, server } from '../../lib/index.mjs' + +let client let cwd = process.cwd() -let sut = join(cwd, 'src', 'index.js') -let client = require(sut) - let { badPort, config, host, path, protocol, service, port } = defaults let mock = join(cwd, 'test', 'mock') let pluginDir = join(mock, 'plugins') let invalidPlugins = join(pluginDir, 'invalid') let p = path => process.platform.startsWith('win') ? 'file://' + path : path +let __filename = url.fileURLToPath(import.meta.url) +let require = module.createRequire(import.meta.url) test('Set up env', async t => { t.plan(2) + let sut = 'file://' + join(cwd, 'src', 'index.js') + client = (await import(sut)).default t.ok(client, 'aws-lite client is present') let started = await server.start() t.ok(started, 'Started server') @@ -182,7 +188,7 @@ test('Plugins - validate input', async t => { test('Plugins - validate service', async t => { t.plan(2) - let plugin = require(join(pluginDir, 'misc', 'unverified-service.js')) + let plugin = import(join(pluginDir, 'misc', 'unverified-service.js')) try { await client({ ...config, plugins: [ plugin ] }) t.fail('Plugin with unverified service should throw') @@ -346,7 +352,7 @@ test('Plugins - error(), error handling', async t => { let responseBody, responseHeaders, responseStatusCode let errorsPlugin = join(pluginDir, 'error.js') - let aws = await client({ ...config, plugins: [ require(errorsPlugin) ] }) + let aws = await client({ ...config, plugins: [ import(errorsPlugin) ] }) // Control try { @@ -508,7 +514,7 @@ test('Plugins - error docs (@aws-lite)', async t => { test('Plugins - disabled methods', async t => { t.plan(3) - let aws = await client({ ...config, plugins: [ require(join(pluginDir, 'misc', 'disabled-methods')) ] }) + let aws = await client({ ...config, plugins: [ import(join(pluginDir, 'misc', 'disabled-methods.js')) ] }) t.ok(aws.lambda.ok, 'Client loaded plugin containing disabled methods') t.notOk(aws.lambda.disabledByFalsy, 'Client did not load method disabled by boolean false') t.notOk(aws.lambda.disabledByParam, `Client did not load method disabled by 'disabled' param`) @@ -545,7 +551,7 @@ test('Plugins - plugin validation', async t => { // Failures try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'invalid-request-method.js')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'invalid-request-method.js')) ] }) } catch (err) { t.match(err.message, /All plugin request methods must be a function/, 'Throw on invalid request method') @@ -553,7 +559,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'invalid-response-method.js')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'invalid-response-method.js')) ] }) } catch (err) { t.match(err.message, /All plugin response methods must be a function/, 'Throw on invalid response method') @@ -561,7 +567,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'invalid-error-method.js')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'invalid-error-method.js')) ] }) } catch (err) { t.match(err.message, /All plugin error methods must be a function/, 'Throw on invalid error method') @@ -569,7 +575,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'invalid-service.js')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'invalid-service.js')) ] }) } catch (err) { t.match(err.message, /Invalid AWS service specified: lolidk/, 'Throw on invalid service') @@ -577,7 +583,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'this-plugin-does-not-exist.js')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'this-plugin-does-not-exist.js')) ] }) } catch (err) { t.match(err.message, /Cannot find module/, 'Throw on missing plugin') @@ -585,7 +591,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'invalid-plugin.js')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'invalid-plugin.js')) ] }) } catch (err) { t.match(err.message, /lol is not defined/, 'Throw on invalid plugin') @@ -593,7 +599,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'invalid-methods-type')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'invalid-methods-type.js')) ] }) } catch (err) { t.match(err.message, /Plugin must export a methods object/, 'Throw on missing methods') @@ -601,7 +607,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'invalid-methods-missing')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'invalid-methods-missing.js')) ] }) } catch (err) { t.match(err.message, /Plugin must export a methods object/, 'Throw on missing methods') @@ -609,7 +615,7 @@ test('Plugins - plugin validation', async t => { } try { - await client({ ...config, plugins: [ require(join(invalidPlugins, 'this-plugin-does-not-exist.js')) ] }) + await client({ ...config, plugins: [ import(join(invalidPlugins, 'this-plugin-does-not-exist.js')) ] }) } catch (err) { t.match(err.message, /Cannot find module/, 'Throw on missing plugin') diff --git a/test/unit/src/index-retries-test.mjs b/test/unit/src/index-retries-test.mjs index 5611b27e..b773f7c7 100644 --- a/test/unit/src/index-retries-test.mjs +++ b/test/unit/src/index-retries-test.mjs @@ -1,11 +1,10 @@ -let { join } = require('node:path') -let http = require('node:http') -let test = require('tape') -let { defaults } = require('../../lib') -let cwd = process.cwd() -let sut = join(cwd, 'src', 'index.js') -let client = require(sut) +import http from 'node:http' +import { join } from 'node:path' +import process from 'node:process' +import test from 'tape' +import { defaults } from '../../lib/index.mjs' +let client let { config, service, port } = defaults let retryServer, serverError @@ -23,6 +22,9 @@ function reset () { test('Set up env', async t => { t.plan(2) + let cwd = process.cwd() + let sut = 'file://' + join(cwd, 'src', 'index.js') + client = (await import(sut)).default t.ok(client, 'aws-lite client is present') retryServer = http.createServer((req, res) => { req.on('data', () => {}) @@ -62,6 +64,7 @@ test('Retries', async t => { t.fail('Expected an error') } catch (err) { + console.log(err) t.equal(requests.length, 1, 'Client did not retry') } @@ -74,6 +77,7 @@ test('Retries', async t => { t.fail('Expected an error') } catch (err) { + console.log(err) t.equal(requests.length, 1, 'Client did not retry') } @@ -87,6 +91,7 @@ test('Retries', async t => { t.fail('Expected an error') } catch (err) { + console.log(err) t.equal(requests.length, retries + 1, 'Client retried, passed through error') } @@ -117,6 +122,7 @@ test('Retries', async t => { t.fail('Expected an error') } catch (err) { + console.log(err) t.equal(requests.length, retries + 1, 'Client retried, passed through error') } @@ -132,6 +138,7 @@ test('Retries', async t => { t.fail('Expected an error') } catch (err) { + console.log(err) t.equal(requests.length, retries + 1, 'Client retried, passed through error') } }) @@ -147,6 +154,7 @@ test('Retries - validation', async t => { t.fail('Expected an error') } catch (err) { + console.log(err) t.match(err.message, /must a number/, 'Errored on retries string value') } }) diff --git a/test/unit/src/index-testing-test.mjs b/test/unit/src/index-testing-test.mjs index c50754d7..7d56ddf2 100644 --- a/test/unit/src/index-testing-test.mjs +++ b/test/unit/src/index-testing-test.mjs @@ -1,10 +1,9 @@ -let { join } = require('node:path') -let test = require('tape') -let { copy, defaults } = require('../../lib') -let cwd = process.cwd() -let sut = join(cwd, 'src', 'index.js') -let client = require(sut) +import { join } from 'node:path' +import process from 'node:process' +import test from 'tape' +import { copy, defaults } from '../../lib/index.mjs' +let client let { config } = defaults let jsonHeaders = { 'content-type': 'application/json' } let rando = () => (Math.random() + 1).toString(36).substring(2) @@ -25,6 +24,9 @@ let mockErr = { test('Set up env', async t => { t.plan(1) + let cwd = process.cwd() + let sut = 'file://' + join(cwd, 'src', 'index.js') + client = (await import(sut)).default t.ok(client, 'aws-lite client is present') }) diff --git a/test/unit/src/lib/index-test.mjs b/test/unit/src/lib/index-test.mjs index 27db3040..5a2f67bd 100644 --- a/test/unit/src/lib/index-test.mjs +++ b/test/unit/src/lib/index-test.mjs @@ -1,18 +1,19 @@ -let { join } = require('node:path') -let test = require('tape') -let cwd = process.cwd() -let sut = join(cwd, 'src', 'lib', 'index.js') -let lib = require(sut) -let { useAWS } = lib +import { join } from 'node:path' +import test from 'tape' +let useAWS function reset () { delete process.env.ARC_ENV delete process.env.ARC_LOCAL delete process.env.ARC_SANDBOX } -test('Set up env', t => { +test('Set up env', async t => { t.plan(1) + let cwd = process.cwd() + let sut = 'file://' + join(cwd, 'src', 'lib', 'index.js') + let lib = await import(sut) + useAWS = lib.useAWS t.ok(useAWS, 'useAWS util is present') })