Skip to content

Commit

Permalink
test: added test to ensure doc-check isn't done on windows (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed May 23, 2023
1 parent be4a239 commit 429165b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 41 deletions.
87 changes: 46 additions & 41 deletions src/document-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,61 @@ const tasks = new Listr(
* @param {Task} task
*/
task: async (ctx, task) => {
const configPath = './tsconfig-doc-check.aegir.json'
const isWindows = process.platform === 'win32'

let userTSConfig = {}
let markdownFiles = ['README.md']
if (!isWindows) {
const configPath = './tsconfig-doc-check.aegir.json'

if (ctx.tsConfigPath && ctx.tsConfigPath !== '.') {
userTSConfig = readJson(`${ctx.tsConfigPath}/tsconfig.json`)
} else {
userTSConfig = readJson(fromRoot('tsconfig.json'))
}
let userTSConfig = {}
let markdownFiles = ['README.md']

if (ctx.inputFiles) {
markdownFiles = await globby(ctx.inputFiles)
}
if (ctx.tsConfigPath && ctx.tsConfigPath !== '.') {
userTSConfig = readJson(`${ctx.tsConfigPath}/tsconfig.json`)
} else {
userTSConfig = readJson(fromRoot('tsconfig.json'))
}

if (ctx.inputFiles) {
markdownFiles = await globby(ctx.inputFiles)
}

try {
fs.writeJsonSync(
configPath,
merge.apply({ concatArrays: true }, [
userTSConfig,
{
compilerOptions: {
target: 'esnext',
module: 'esnext',
noImplicitAny: true,
noEmit: true
try {
fs.writeJsonSync(
configPath,
merge.apply({ concatArrays: true }, [
userTSConfig,
{
compilerOptions: {
target: 'esnext',
module: 'esnext',
noImplicitAny: true,
noEmit: true
}
}
}
])
)
])
)

const results = await compileSnippets({ markdownFiles, project: configPath })
const results = await compileSnippets({ markdownFiles, project: configPath })

results.forEach((result) => {
if (result.error) {
process.exitCode = 1
console.log(kleur.red().bold(`Error compiling example code block ${result.index} in file ${result.file}:`))
console.log(formatError(result.error))
console.log(kleur.blue().bold('Original code:'))
console.log(formatCode(result.snippet, result.linesWithErrors))
}
})
} catch (err) {
console.log('Error in trying to compile Typescript code', err)
} finally {
fs.removeSync(configPath)
fs.removeSync(fromRoot('dist', 'tsconfig-doc-check.aegir.tsbuildinfo'))
results.forEach((result) => {
if (result.error) {
process.exitCode = 1
console.log(kleur.red().bold(`Error compiling example code block ${result.index} in file ${result.file}:`))
console.log(formatError(result.error))
console.log(kleur.blue().bold('Original code:'))
console.log(formatCode(result.snippet, result.linesWithErrors))
}
})
} catch (err) {
console.log('Error in trying to compile Typescript code', err)
} finally {
fs.removeSync(configPath)
fs.removeSync(fromRoot('dist', 'tsconfig-doc-check.aegir.tsbuildinfo'))
}
} else {
throw new Error(kleur.red('The underlying plugin used for TS-doc checks currently does not support Windows OS (See Github issue https://github.com/bbc/typescript-docs-verifier/issues/26). Skipping document check.'))
}
}

}
],
{
Expand Down
10 changes: 10 additions & 0 deletions test/document-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,15 @@ describe('document check', () => {
.with.property('stderr')
.that.include('no such file or directory')
})
} else {
// #TODO remove when https://github.com/bbc/typescript-docs-verifier/issues/26 is resolved
it('should report incompatability on windows until the TS doc path resolution issue is resolved', async () => {
const cwd = path.join(__dirname, 'fixtures/document-check/pass')

await expect(execa(bin, ['doc-check', '--inputFiles', `${cwd}/*.md`, '--tsConfigPath', `${cwd}`]))
.to.eventually.be.rejected()
.with.property('stderr')
.that.include('The underlying plugin used for TS-doc checks currently does not support Windows OS')
})
}
})

0 comments on commit 429165b

Please sign in to comment.