Skip to content

Commit

Permalink
chore: resolve running test cases on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
msudgh committed Aug 10, 2024
1 parent 899c65d commit 0e3e8de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "pnpm run lint",
"prepack": "oclif manifest && pnpm run build:release && pnpm run test:unit",
"test:unit": "pnpm run build && CI=1 mocha",
"test:unit": "pnpm run build && mocha",
"test:coverage": "nyc npm run test:unit"
},
"keywords": [
Expand Down
2 changes: 2 additions & 0 deletions src/commands/config/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { expect } from 'chai'
import { existsSync } from 'fs'
import { destroyConfigMockFile, getTmpConfigFilePath, runCommand } from '../../utils/testing'

process.env.CI = 'true'

describe('Command: config init', () => {
beforeEach(async () => {
const tmpConfigFilePath = getTmpConfigFilePath()
Expand Down
12 changes: 9 additions & 3 deletions src/utils/testing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { exec, ExecException } from 'child_process'
import { rm } from 'fs/promises'
import { tmpdir } from 'os'
import { platform, tmpdir } from 'os'
import path from 'path'
import { OVM_CONFIG_FILENAME } from './constants'

Expand All @@ -13,8 +13,15 @@ export const runCommand = async (
command: string,
dev = false,
): Promise<CommandResult | (ExecException | null)> => {
const formattedCommand = `./bin/${dev ? 'dev' : 'run'}.js ${command}`
return new Promise((resolve, reject) => {
const detectedPlatform = platform()
const runnerExt = detectedPlatform === 'win32' ? 'cmd' : 'js'
const runnerType = dev ? 'dev' : 'run'
const runnerFilePath = `${runnerType}.${runnerExt}`
const formattedCommand =
detectedPlatform === 'win32'
? `bin/${runnerFilePath} ${command}`
: `./bin/${runnerFilePath} ${command}`
exec(formattedCommand, (error, stdout, stderr) => {
if (error) {
reject(error)
Expand All @@ -28,7 +35,6 @@ export const getTmpConfigFilePath = () => {
return path.join(tmpdir(), OVM_CONFIG_FILENAME)
}


export const destroyConfigMockFile = async (path: string) => {
await rm(path, { force: true })
}

0 comments on commit 0e3e8de

Please sign in to comment.