From dcc4ecd0626b04005ecdb1f323fe463eaa2c6cc1 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Fri, 10 Sep 2021 17:23:23 +1000 Subject: [PATCH] chore: make tests work properly on windows, moar doc --- README.md | 2 ++ test/test-parse.js | 13 +++++++++++-- types/parse.d.ts.map | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9d95152..26f93e0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/test/test-parse.js b/test/test-parse.js index 5f32c1c..f1a0d4f 100644 --- a/test/test-parse.js +++ b/test/test-parse.js @@ -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) diff --git a/types/parse.d.ts.map b/types/parse.d.ts.map index e5b16e1..41696ed 100644 --- a/types/parse.d.ts.map +++ b/types/parse.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../parse.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;GAGG;AACH,gCAHW,MAAM,GACJ,QAAQ,CA6EpB;sBAnFY,OAAO,aAAa,EAAE,OAAO;uBAC7B,OAAO,aAAa,EAAE,QAAQ"} \ No newline at end of file +{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../parse.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;GAGG;AACH,gCAHW,MAAM,GACJ,QAAQ,CA8EpB;sBApFY,OAAO,aAAa,EAAE,OAAO;uBAC7B,OAAO,aAAa,EAAE,QAAQ"} \ No newline at end of file