Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Fixes tests on windows while preserving intent of tests. (#97)
Browse files Browse the repository at this point in the history
* Fixes tests on windows while preserving intent of tests.

* lints

Co-authored-by: Mike Whit <mikegwhit@users.noreply.github.com>
  • Loading branch information
mikegwhit and mikegwhit committed Sep 11, 2020
1 parent fb116bb commit 1d7547f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/cdk/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('MiraBootstrap', () => {
const miraBootstrapInstance = new MiraBootstrap()
it('has resolved cdkCommand path', () => {
const validCdkPathPart = 'node_modules/aws-cdk/bin/cdk'
expect(new RegExp(validCdkPathPart, 'g').test(miraBootstrapInstance.cdkCommand)).toBeTruthy()
expect(new RegExp(validCdkPathPart, 'g').test(miraBootstrapInstance.cdkCommand.replace(/\\/g, '/'))).toBeTruthy()
})
it('has resolved docsify path', () => {
const validCdkPathPart = 'node_modules/docsify-cli/bin/docsify'
expect(new RegExp(validCdkPathPart, 'g').test(miraBootstrapInstance.docsifyCommand)).toBeTruthy()
expect(new RegExp(validCdkPathPart, 'g').test(miraBootstrapInstance.docsifyCommand.replace(/\\/g, '/'))).toBeTruthy()
})
it('has app initialized', () => {
expect(miraBootstrapInstance.app instanceof MiraApp).toBeTruthy()
Expand Down
14 changes: 12 additions & 2 deletions src/error-logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
import cp from 'child_process'
import fs from 'fs'
import path from 'path'
/**
Expand Down Expand Up @@ -53,8 +54,17 @@ export default class ErrorLogger {
.filter((file) => {
return file.match(/mira-errors-\d{12}\.log$/)
})
.map((file) => {
return unlink(file)
.map(async (file) => {
return unlink(file).catch(() =>
Promise.resolve(() => {
// Windows fix, sometimes this will still generate a non-zero exit
// code but will also delete the file (intended action). Some
// Windows users may not have installed MiniGW / WSL and this will
// also fail.
try { cp.execSync(`rm -f ${file}`) } catch (e) {
// NOOP
}
}))
})
await Promise.all(promises)
}
Expand Down
6 changes: 3 additions & 3 deletions src/transpiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ test('should throw if no tsconfig file is found', () => {

test('should find correct tsconfig.json file', async () => {
const t = new Transpiler('sampleFile.ts')
const root = path.join(__dirname, '..')
const res = await t.findTSConfigFile(root)
expect(res).toBe(`${root}/tsconfig.json`)
const root = path.resolve(path.join(__dirname, '..'))
const res = await t.findTSConfigFile(root) || ''
expect(path.resolve(`${root}/${res}`)).toBe(path.resolve(`${root}/tsconfig.json`))
})

test('should change extension to file', () => {
Expand Down
12 changes: 8 additions & 4 deletions src/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Transpiler {
return new Promise((resolve, reject) => {
exec(command, {
cwd: process.cwd()
}, (err: Error|null) => {
}, (err: Error | null) => {
if (err) {
return reject(err)
}
Expand All @@ -44,10 +44,14 @@ class Transpiler {
return this.filePath.substring(0, this.filePath.length - 2) + newExtension
}

public async findTSConfigFile (start: string): Promise<string|null> {
public async findTSConfigFile (start: string): Promise<string | null> {
return new Promise((resolve, reject) => {
glob(`${start}/**/tsconfig.json`, {
ignore: '/**/node_modules/**'
glob('**/tsconfig.json', {
cwd: start,
ignore: [
'/**/node_modules/**',
'node_modules/**'
]
}, (err, matches) => {
if (err) {
return reject(err)
Expand Down

0 comments on commit 1d7547f

Please sign in to comment.