Skip to content

Commit

Permalink
chore: make tests work properly on windows, moar doc
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Sep 10, 2021
1 parent 805e176 commit dcc4ecd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ Ideally when we're relying on text files for test data input we'd want to have b

So, testmark takes a rather brute-force approach to this problem and just strips out carriage return characters when they appear with a line-ending. In practice this _may_ impact the byte-perfect requirements for test fixtures, so you should be careful when using data that strays outside of standard printable character range, especially when control characters get involved. This is a text file format, if your data isn't text, then make it text by encoding in hex or base64 or something that reduces the character set to the safe range.

The `Document#original` property and `toString()` function are going to result in text that only uses UNIX line endings (`\n`). So even your input document will be transformed if it does a round-trip through testmark on Windows. Be warned!

## Note about the package name

Yes, `.js` extensions to packages such, but once upon a time, [Mark made a test](https://www.npmjs.com/package/test-mark) package and published it to npm, with only a package.json. npm now includes automatic typosquatting detection which they apparently cannot manually override, so nobody can publish a `testmark` package because of this. npm also refuses to remove `test-mark` even though it is a trivial package with no code in it which is in contravention with npm rules: ["Package names are considered squatted if the package has no genuine function."](https://docs.npmjs.com/policies/disputes). Yay.
Expand Down
13 changes: 11 additions & 2 deletions test/test-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,28 @@ const exampleMdExpectedHunks = [
describe('Read', () => {
/** @type {string} */
let exampleMdOriginal
let isWindows = false

before(async () => {
const exampleMd = new URL('../example.md', import.meta.url)
exampleMdOriginal = await fs.promises.readFile(exampleMd, 'utf8')
isWindows = exampleMdOriginal.includes('\r\n')
})

it('can parse example.md', async () => {
const doc = parse(exampleMdOriginal)
assert.deepStrictEqual(exampleMdExpectedHunks, doc.dataHunks)
assert.deepStrictEqual(toString(doc), exampleMdOriginal)
if (isWindows) {
assert.deepStrictEqual(toString(doc), exampleMdOriginal)
} else {
assert.deepStrictEqual(toString(doc).replace('\n', '\r\n'), exampleMdOriginal)
}
})

it('can parse example.md as windows', async () => {
it('can parse example.md as windows', async function () {
if (isWindows) { // skip test on windows
return this.skip()
}
const exampleMdOriginalWindows = exampleMdOriginal.replace(/\r?\n/g, '\r\n')
const doc = parse(exampleMdOriginalWindows)
assert.deepStrictEqual(exampleMdExpectedHunks, doc.dataHunks)
Expand Down
2 changes: 1 addition & 1 deletion types/parse.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dcc4ecd

Please sign in to comment.