diff --git a/test/fixtures/basic-comments/expected.json b/test/fixtures/basic-comments/expected.json new file mode 100644 index 0000000..5dbfe9f --- /dev/null +++ b/test/fixtures/basic-comments/expected.json @@ -0,0 +1 @@ +{ "node": "v20" } diff --git a/test/fixtures/basic-invalid/expected.json b/test/fixtures/basic-invalid/expected.json new file mode 100644 index 0000000..a94f1a0 --- /dev/null +++ b/test/fixtures/basic-invalid/expected.json @@ -0,0 +1,4 @@ +[ + "foo", + "bar" +] diff --git a/test/fixtures/basic-with-comment/expected.json b/test/fixtures/basic-with-comment/expected.json new file mode 100644 index 0000000..56e4a6f --- /dev/null +++ b/test/fixtures/basic-with-comment/expected.json @@ -0,0 +1 @@ +{ "node": "21.2" } diff --git a/test/fixtures/basic-with-npm/expected.json b/test/fixtures/basic-with-npm/expected.json new file mode 100644 index 0000000..dede78b --- /dev/null +++ b/test/fixtures/basic-with-npm/expected.json @@ -0,0 +1 @@ +{ "node": "node", "npm": "10" } diff --git a/test/fixtures/basic/expected.json b/test/fixtures/basic/expected.json new file mode 100644 index 0000000..5ef732c --- /dev/null +++ b/test/fixtures/basic/expected.json @@ -0,0 +1 @@ +{ "node": "node" } diff --git a/test/fixtures/duplicate-pairs/expected.json b/test/fixtures/duplicate-pairs/expected.json new file mode 100644 index 0000000..85ccd70 --- /dev/null +++ b/test/fixtures/duplicate-pairs/expected.json @@ -0,0 +1,5 @@ +[ + "node", + "npm=3", + "npm=4" +] diff --git a/test/fixtures/invalid/expected.json b/test/fixtures/invalid/expected.json new file mode 100644 index 0000000..832876d --- /dev/null +++ b/test/fixtures/invalid/expected.json @@ -0,0 +1,3 @@ +[ + "a=b" +] diff --git a/test/fixtures/only-comments/expected.json b/test/fixtures/only-comments/expected.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/test/fixtures/only-comments/expected.json @@ -0,0 +1 @@ +[] diff --git a/test/fixtures/pre-normalized/expected.json b/test/fixtures/pre-normalized/expected.json new file mode 100644 index 0000000..ad56ba0 --- /dev/null +++ b/test/fixtures/pre-normalized/expected.json @@ -0,0 +1,4 @@ +[ + "node=foo", + "npm=bar" +] diff --git a/test/index.mjs b/test/index.mjs index 5a045ba..91fbe9d 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -1,6 +1,6 @@ import { spawnSync } from 'child_process'; import { join } from 'path'; -import { readdirSync } from 'fs'; +import { readFileSync, readdirSync } from 'fs'; import test from 'tape'; @@ -34,7 +34,7 @@ test('nvmrc', async (t) => { t.test(`fixture ${fixture}`, (st) => { const cwd = join(fixtureDir, fixture); - const { stdout, status } = spawnSync(`${bin}`, { cwd }); + const { status, stdout } = spawnSync(`${bin}`, { cwd }); st.equal(status, 0, 'yields a zero exit code'); @@ -42,6 +42,10 @@ test('nvmrc', async (t) => { st.doesNotThrow(() => JSON.parse(stripped), `fixture ${fixture} is valid, yields ${stripped.replace(/\n\s*/g, ' ')}`); + const expected = JSON.parse(`${readFileSync(join(cwd, 'expected.json'))}`); + + st.deepEqual(JSON.parse(stripped), expected, `fixture ${fixture} yields expected result`); + st.end(); }); } @@ -67,6 +71,10 @@ test('nvmrc', async (t) => { 'non-commented content parsed:', ]); + const expected = JSON.parse(`${readFileSync(join(cwd, 'expected.json'))}`); + + st.deepEqual(lines.slice(6), expected, `fixture ${fixture} produces expected warning lines`); + st.end(); }); }