From 37cff0ea46fefb26ae034248d0fa995d49d4180c Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Mon, 29 May 2023 20:40:41 -0700 Subject: [PATCH] fix cjs artifact - fixes #133 --- package.json | 3 ++- src/cjs/index.ts | 3 ++- tests/interop/cjs.test.ts | 17 +++++++++++++++++ tests/interop/package.json | 3 +++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/interop/cjs.test.ts create mode 100644 tests/interop/package.json diff --git a/package.json b/package.json index 8dd20fe..e4c420c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "compile": "tsc --build tsconfig.json", "copy": "cp src/cjs/package.json build/cjs", "test:eslint": "eslint src tests", - "test:unit": "vitest" + "test:unit": "vitest", + "watch": "npm run compile -- --watch" }, "dependencies": { "@wdio/globals": "^8.3.2", diff --git a/src/cjs/index.ts b/src/cjs/index.ts index bf4aa6b..054f34c 100644 --- a/src/cjs/index.ts +++ b/src/cjs/index.ts @@ -1,4 +1,5 @@ exports.default = class CJSGmailService { + private isCJS = true private instance?: any constructor(options: never) { @@ -9,6 +10,6 @@ exports.default = class CJSGmailService { async before (...args: never[]) { const instance = await this.instance - return instance.onPrepare(...args) + return instance.before(...args) } } diff --git a/tests/interop/cjs.test.ts b/tests/interop/cjs.test.ts new file mode 100644 index 0000000..c3e315f --- /dev/null +++ b/tests/interop/cjs.test.ts @@ -0,0 +1,17 @@ +import { vi, test, expect} from 'vitest' +// eslint-disable-next-line @typescript-eslint/no-var-requires, import/extensions +const Service = require('../../') + +vi.mock('../../src/service.js', () => class { + before () { + return 'beforeCalled' + } +}) + +test('should export the right method', async () => { + const service = new Service.default({}) + const browser = { addCommand: vi.fn() } + await service.before(null, null, browser) + expect(service['isCJS']).toBe(true) + expect(browser.addCommand).toBeCalledTimes(1) +}) diff --git a/tests/interop/package.json b/tests/interop/package.json new file mode 100644 index 0000000..5bbefff --- /dev/null +++ b/tests/interop/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +}