Skip to content

Commit

Permalink
fix cjs artifact - fixes #133
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed May 30, 2023
1 parent e30c0bc commit 37cff0e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/cjs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
exports.default = class CJSGmailService {
private isCJS = true
private instance?: any

constructor(options: never) {
Expand All @@ -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)
}
}
17 changes: 17 additions & 0 deletions tests/interop/cjs.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
3 changes: 3 additions & 0 deletions tests/interop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

0 comments on commit 37cff0e

Please sign in to comment.