Skip to content

Commit e4a9e5e

Browse files
committed
test: upgrade to oclif test v4 and add jest
1 parent 9180978 commit e4a9e5e

13 files changed

+7556
-6375
lines changed

.mocharc.json

-15
This file was deleted.

jest.config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { JestConfigWithTsJest } from 'ts-jest'
2+
3+
const jestConfig: JestConfigWithTsJest = {
4+
preset: 'ts-jest/presets/default-esm',
5+
}
6+
7+
export default jestConfig

package-lock.json

+7,494-6,255
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@
5050
"underscore.string": "^3.3.6"
5151
},
5252
"devDependencies": {
53+
"@jest/globals": "^29.7.0",
5354
"@oclif/prettier-config": "^0.2.1",
54-
"@oclif/test": "^3",
55+
"@oclif/test": "^4",
5556
"@types/adm-zip": "^0.5.5",
5657
"@types/archiver": "^6.0.2",
5758
"@types/chai": "^4",
5859
"@types/debug": "^4.1.12",
60+
"@types/jest": "^29.5.12",
5961
"@types/lodash.assign": "^4.2.9",
60-
"@types/mocha": "^10",
6162
"@types/node": "20.11.0",
6263
"@types/underscore.string": "^0.0.41",
6364
"chai": "^4",
@@ -66,9 +67,10 @@
6667
"eslint-config-oclif-typescript": "^3",
6768
"eslint-config-prettier": "^9.1.0",
6869
"eslint-plugin-jsdoc": "^48.0.2",
69-
"mocha": "^10",
70+
"jest": "^29.7.0",
7071
"oclif": "^4.1.3",
7172
"shx": "^0.3.4",
73+
"ts-jest": "^29.1.3",
7274
"ts-node": "^10.9.2",
7375
"tsx": "^4.7.3",
7476
"typescript": "^5"
@@ -96,7 +98,7 @@
9698
"posttest": "npm run lint",
9799
"prepack": "npm run build && oclif manifest && oclif readme",
98100
"prepare": "npm run build",
99-
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
101+
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
100102
"version": "oclif readme && git add README.md"
101103
}
102-
}
104+
}

src/AuthCommand.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Command } from '@oclif/core'
22
import axios from 'axios'
33
import createDebug from 'debug'
4-
import { CodeGenieConfig, getCodeGenieConfig, updateCodeGenieConfig } from './config.js'
5-
import { getOpenIdClient } from './openid-client.js'
4+
import { CodeGenieConfig, getCodeGenieConfig, updateCodeGenieConfig } from './config'
5+
import { getOpenIdClient } from './openid-client'
66

77
const API_ENDPOINT = process.env.API_ENDPOINT || 'https://api.codegenie.codes'
88
axios.defaults.baseURL = API_ENDPOINT

src/commands/generate.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { describe, expect, test } from '@jest/globals'
2+
import { runCommand } from '@oclif/test'
3+
4+
describe('generate', () => {
5+
test('help', async () => {
6+
const { stdout } = await runCommand(['generate', '--help'])
7+
expect(stdout).toMatch(/USAGE/)
8+
})
9+
})

src/commands/generate.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import axios, { AxiosError } from 'axios'
44
import AdmZip from 'adm-zip'
55
import { cosmiconfig } from 'cosmiconfig'
66
import createDebug from 'debug'
7-
import { awsCredentialsFileExists } from '../aws-creds.js'
8-
import sleep from '../sleep.js'
7+
import { awsCredentialsFileExists } from '../aws-creds'
8+
import sleep from '../sleep'
99
import { execSync } from 'node:child_process'
1010
import { cwd } from 'node:process'
11-
import { AppDefinition } from '../input/types.js'
12-
import { generateIcons } from '../generate-icons.js'
11+
import { AppDefinition } from '../input/types'
12+
import { generateIcons } from '../generate-icons'
1313
import { dirname, join, resolve } from 'node:path'
1414
import { inspect } from 'node:util'
1515
import { copyFile, mkdir } from 'node:fs/promises'
1616
import { fileURLToPath } from 'node:url'
17-
import { AuthCommand } from '../AuthCommand.js'
18-
import { convertCliAppDefinitionToDatabaseModel } from '../convert-cli-app-definition-to-database-model.js'
17+
import { AuthCommand } from '../AuthCommand'
18+
import { convertCliAppDefinitionToDatabaseModel } from '../convert-cli-app-definition-to-database-model'
1919
const __dirname = dirname(fileURLToPath(import.meta.url))
2020

2121
const debug = createDebug('codegenie:generate')

src/commands/login.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { Command, ux } from '@oclif/core'
44
import { generators } from 'openid-client'
55
import open from 'open'
66
import createDebug from 'debug'
7-
import sleep from '../sleep.js'
8-
import { updateCodeGenieConfig } from '../config.js'
9-
import { REDIRECT_URL, getOpenIdClient } from '../openid-client.js'
10-
import { getRandom } from '../get-random.js'
7+
import sleep from '../sleep'
8+
import { updateCodeGenieConfig } from '../config'
9+
import { REDIRECT_URL, getOpenIdClient } from '../openid-client'
10+
import { getRandom } from '../get-random'
1111

1212
const debug = createDebug('codegenie:Login')
1313

test/commands/generate.test.ts

-35
This file was deleted.

test/commands/login.test.ts

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { expect, test } from '@oclif/test'
2-
import { convertCliAppDefinitionToDatabaseModel } from '../src/convert-cli-app-definition-to-database-model.js'
3-
import { AppDefinition } from '../src/input/types.js'
1+
import { describe, expect, test } from '@jest/globals'
2+
import { convertCliAppDefinitionToDatabaseModel } from '../src/convert-cli-app-definition-to-database-model'
3+
import type { AppDefinition } from '../src/input/types'
44

55
const appDefinition: AppDefinition = {
66
appId: 'xxx',
@@ -25,25 +25,23 @@ const appDefinition: AppDefinition = {
2525
entities: {},
2626
}
2727
describe('convertCliAppDefinitionToDatabaseModel', () => {
28-
test.it('converts CLI to DB', () => {
28+
test('convertCliAppDefinitionToDatabaseModel', () => {
2929
const converted = convertCliAppDefinitionToDatabaseModel({ appDefinition })
30-
expect(JSON.stringify(converted)).to.eq(
31-
JSON.stringify({
32-
appId: 'xxx',
33-
name: 'Name',
34-
description: 'Description',
35-
region: 'us-west-2',
36-
domainName: 'example.com',
37-
appDomainName: 'app.example.com',
38-
apiDomainName: 'api.example.com',
39-
verifyUserEmail: '[email protected]',
40-
organizationInviteEmail: '[email protected]',
41-
alarmNotificationEmail: '[email protected]',
42-
defaultAuthRouteEntityName: 'App',
43-
permissionModel: 'Organization',
44-
themePrimaryColor: '#579ddd',
45-
authIdentityProviders: ['Google'],
46-
})
47-
)
30+
expect(converted).toEqual({
31+
appId: 'xxx',
32+
name: 'Name',
33+
description: 'Description',
34+
region: 'us-west-2',
35+
domainName: 'example.com',
36+
appDomainName: 'app.example.com',
37+
apiDomainName: 'api.example.com',
38+
verifyUserEmail: '[email protected]',
39+
organizationInviteEmail: '[email protected]',
40+
alarmNotificationEmail: '[email protected]',
41+
defaultAuthRouteEntityName: 'App',
42+
permissionModel: 'Organization',
43+
themePrimaryColor: '#579ddd',
44+
authIdentityProviders: ['Google'],
45+
})
4846
})
4947
})

test/tsconfig.json

-7
This file was deleted.

tsconfig.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"compilerOptions": {
33
"declaration": true,
4-
"module": "Node16",
4+
"module": "es2022",
55
"outDir": "dist",
66
"rootDir": "src",
77
"strict": true,
88
"target": "es2022",
9-
"moduleResolution": "node16",
9+
"moduleResolution": "Node",
1010
"composite": true,
1111
"sourceMap": true,
12-
"declarationMap": true
12+
"declarationMap": true,
13+
"esModuleInterop": true,
14+
"allowJs": true,
15+
"types": ["jest"]
1316
},
14-
"include": ["./src/**/*"],
15-
"ts-node": {
16-
"esm": true
17-
}
17+
"include": ["./src/**/*"]
1818
}

0 commit comments

Comments
 (0)