Skip to content

Commit

Permalink
[Tests] add more assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 6, 2024
1 parent 3a92b47 commit 41a8ad6
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/fixtures/basic-comments/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "node": "v20" }
4 changes: 4 additions & 0 deletions test/fixtures/basic-invalid/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"foo",
"bar"
]
1 change: 1 addition & 0 deletions test/fixtures/basic-with-comment/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "node": "21.2" }
1 change: 1 addition & 0 deletions test/fixtures/basic-with-npm/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "node": "node", "npm": "10" }
1 change: 1 addition & 0 deletions test/fixtures/basic/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "node": "node" }
5 changes: 5 additions & 0 deletions test/fixtures/duplicate-pairs/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"node",
"npm=3",
"npm=4"
]
3 changes: 3 additions & 0 deletions test/fixtures/invalid/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"a=b"
]
1 change: 1 addition & 0 deletions test/fixtures/only-comments/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
4 changes: 4 additions & 0 deletions test/fixtures/pre-normalized/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"node=foo",
"npm=bar"
]
12 changes: 10 additions & 2 deletions test/index.mjs
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -34,14 +34,18 @@ 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');

const stripped = stripColors(`${stdout}`);

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();
});
}
Expand All @@ -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();
});
}
Expand Down

0 comments on commit 41a8ad6

Please sign in to comment.