Skip to content

Commit ba02809

Browse files
committed
Normalise line-endings in the test suite to enable cross-platform testing
1 parent dceef69 commit ba02809

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

.github/workflows/node.js.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Node.js CI
44

55
on:
66
push:
7-
branches: [ master ]
7+
branches: [ master, next ]
88
pull_request:
99
branches: [ master ]
1010

@@ -15,7 +15,7 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
os: [ubuntu-latest] # Remove windows as tests fail on `\r\n` style newlines
18+
os: [ubuntu-latest, windows-latest] # Remove windows as tests fail on `\r\n` style newlines
1919
node-version: [12, 14, 16, 18, 20, 22, 23]
2020

2121
steps:
@@ -28,3 +28,4 @@ jobs:
2828
- run: npm install
2929
- run: npm i -g @75lb/nature
3030
- run: npm run test:ci
31+

package-lock.json

+15-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/caching.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ test.set('.explain({ files, cache: true })', async function () {
1111
const f = new Fixture('class-all')
1212
jsdoc.cache.dir = 'tmp/test/cache1'
1313
await jsdoc.cache.clear()
14-
const output = await jsdoc.explain({ files: f.sourcePath, cache: true })
14+
let output = await jsdoc.explain({ files: f.sourcePath, cache: true })
15+
output = Fixture.normaliseNewLines(output)
1516
const cachedFiles = readdirSync(jsdoc.cache.dir)
1617
.map(file => path.resolve(jsdoc.cache.dir, file))
1718
a.equal(cachedFiles.length, 1)

test/explain.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const [test, only, skip] = [new Map(), new Map(), new Map()]
77

88
test.set('.explain({ files })', async function () {
99
const f = new Fixture('class-all')
10-
const output = await jsdoc.explain({ files: f.sourcePath })
10+
let output = await jsdoc.explain({ files: f.sourcePath })
11+
output = Fixture.normaliseNewLines(output)
1112
a.deepEqual(output, f.getExpectedOutput(output))
1213
})
1314

1415
test.set('.explain({ source })', async function () {
1516
const f = new Fixture('class-all')
16-
const output = await jsdoc.explain({ source: f.getSource() })
17+
let output = await jsdoc.explain({ source: f.getSource() })
18+
output = Fixture.normaliseNewLines(output)
1719
a.deepEqual(output, f.getExpectedOutput(output))
1820
})
1921

test/fixture/folder with spaces/jsdoc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../node_modules/.bin/jsdoc

test/lib/fixture.js

+10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ class Fixture {
4444
}
4545
})
4646
}
47+
48+
static normaliseNewLines (doclets) {
49+
const input = JSON.stringify(doclets)
50+
/* Normalise all newlines to posix style to avoid differences while testing on Windows */
51+
let result = input.replace(/\r?\n/gm, '\n')
52+
/* Additional check for naked \r characters created by jsdoc */
53+
/* See: https://github.com/jsdoc2md/dmd/issues/102 */
54+
result = result.replace(/\r(?!\n)/g, '\n')
55+
return JSON.parse(result)
56+
}
4757
}
4858

4959
export default Fixture

0 commit comments

Comments
 (0)