From 0190d2448873e9e16ac08358fa8a4a52aff13cf1 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 29 May 2024 19:10:16 +0200 Subject: [PATCH] Add tests --- package.json | 4 ++++ test/hook/date-fns.mjs | 11 +++++++++++ test/hook/got.mjs | 16 ++++++++++++++++ test/hook/openai.mjs | 11 +++++++++++ test/hook/react-email-components.mjs | 16 ++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 test/hook/date-fns.mjs create mode 100644 test/hook/got.mjs create mode 100644 test/hook/openai.mjs create mode 100644 test/hook/react-email-components.mjs diff --git a/package.json b/package.json index 2daef3d..2b6ede2 100644 --- a/package.json +++ b/package.json @@ -36,15 +36,19 @@ "@babel/core": "^7.23.7", "@babel/eslint-parser": "^7.23.3", "@babel/plugin-syntax-import-assertions": "^7.23.3", + "@react-email/components": "^0.0.19", "@types/node": "^18.0.6", "c8": "^7.8.0", + "date-fns": "^3.6.0", "eslint": "^8.55.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.29.0", "eslint-plugin-n": "^16.4.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^6.1.1", + "got": "^14.3.0", "imhotap": "^2.1.0", + "openai": "^4.47.2", "ts-node": "^10.9.1", "typescript": "^4.7.4" }, diff --git a/test/hook/date-fns.mjs b/test/hook/date-fns.mjs new file mode 100644 index 0000000..ebd4c8d --- /dev/null +++ b/test/hook/date-fns.mjs @@ -0,0 +1,11 @@ +import { format, parse } from 'date-fns' +import Hook from '../../index.js' + +Hook((exports, name) => { + if (name === 'date-fns') { + // + } +}) + +console.assert(format, parse) + diff --git a/test/hook/got.mjs b/test/hook/got.mjs new file mode 100644 index 0000000..2ec0ce6 --- /dev/null +++ b/test/hook/got.mjs @@ -0,0 +1,16 @@ +import got, { Options } from 'got' +import { strictEqual } from 'assert' +import Hook from '../../index.js' + +Hook((exports, name) => { + if (name === 'got' && 'Options' in exports) { + exports.Options = 'nothing' + } +}) + +strictEqual(typeof got, 'function') +strictEqual(typeof got.post, 'function') +strictEqual(typeof got.stream, 'function') +strictEqual(typeof got.extend, 'function') + +strictEqual(Options, 'nothing') diff --git a/test/hook/openai.mjs b/test/hook/openai.mjs new file mode 100644 index 0000000..9bc5372 --- /dev/null +++ b/test/hook/openai.mjs @@ -0,0 +1,11 @@ +import OpenAI from 'openai' +import Hook from '../../index.js' + +Hook((exports, name) => { + if (name === 'openai') { + console.assert(name, exports) + } +}) + +console.assert(OpenAI) + diff --git a/test/hook/react-email-components.mjs b/test/hook/react-email-components.mjs new file mode 100644 index 0000000..56d99d7 --- /dev/null +++ b/test/hook/react-email-components.mjs @@ -0,0 +1,16 @@ +import * as lib from '@react-email/components' +import { Heading } from '@react-email/components' +import Hook from '../../index.js' +import { strictEqual } from 'assert' + +Hook((exports, name) => { + if (name.match(/@react-email\/components/)) { + exports.Heading = function wrappedHeading () { + return 'heading-wrapped' + } + } +}) + +strictEqual(typeof lib.Button, 'function') +strictEqual(lib.Heading(), 'heading-wrapped') +strictEqual(Heading(), 'heading-wrapped') -- 2.43.3