Skip to content

Commit

Permalink
Make .gitignore match directories, add fake jsdoc
Browse files Browse the repository at this point in the history
This is why so many tests were failing as though they couldn't find
test/fixtures/fakeJsdoc. It was never added to the repo, because
.gitignore matched it.

Adding a trailing `/` to `jsdoc/` and other entries resolves this
particular issue.
  • Loading branch information
mbland committed Dec 28, 2023
1 parent e8e01ce commit bcb0bf9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 9 deletions.
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.DS_Store
.idea
.vscode
.idea/
.vscode/
TESTS-*.xml
build
coverage
dist
jsdoc
node_modules
out
build/
coverage/
dist/
jsdoc/
node_modules/
out/
pnpm-debug.log
tmp
tmp/
*.log
69 changes: 69 additions & 0 deletions test/fixtures/fakeJsdoc/jsdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env node
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

/**
* Fake jsdoc implementation for testing
*/

import { mkdir, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { exit } from 'node:process'

try {
const {willGenerate, destination, exitCode} = parseArgs(process.argv.slice(2))

if (willGenerate && exitCode === 0) {
const newSubDir = path.join(destination, 'new-subdir')
await mkdir(newSubDir, {recursive: true})
await writeFile(path.join(newSubDir, 'index.html'), 'New Hotness')
}
exit(exitCode)

} catch (err) {
console.error(err)
exit(1)
}

/**
* The parameters parsed from process.argv by parseArgs()
* @typedef {object} ArgsResult
* @property {string} destination - the JSDoc destination directory
* @property {boolean} willGenerate - true unless -h or --no-input-files present
* @property {number} exitCode - the value of --exit-code or 0 by default
*/

/**
* Parses fake jsdoc arguments
* @param {string[]} argv - command line arguments
* @returns {ArgsResult} - parameters determining fake jsdoc behavior
*/
function parseArgs(argv) {
let destination = null
let willGenerate = true
let exitCode = 0

for (let i = 0; i !== argv.length; ++i) {
const arg = argv[i]
const nextArg = argv[i+1]

switch (arg) {
case '-d':
destination = nextArg
break

case '-h':
case '--no-input-files':
willGenerate = false
break

case '--exit-code':
exitCode = nextArg
break
}
}
return {willGenerate, destination, exitCode}
}

0 comments on commit bcb0bf9

Please sign in to comment.