Skip to content

Commit

Permalink
Merge pull request #1 from cto-af/test
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
hildjj authored Oct 7, 2024
2 parents 6bd3073 + a709a95 commit 1d41049
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"eslint-plugin-jsdoc": "50.3.1",
"eslint-plugin-markdown": "5.1.0",
"package-extract": "2.3.0",
"snappy-snaps": "1.1.0",
"typedoc": "0.26.8",
"typescript": "5.6.2",
"typescript-eslint": "8.8.1"
Expand Down
44 changes: 44 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 8 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Data Snap v1

exports[`good`] = {
"data": "Test generation:\n\n\u003C!-- Rule Table Start --\u003E\n| **Rule Name** | **Description** | **Recommended** |\n| :- | :- | :-: |\n| [`foo`](.\u002Fdocs\u002Frules\u002Ffoo.md) | Foo test | yes |\n| [`bar`](.\u002Fdocs\u002Frules\u002Fbar.md) | Bar test | no |\n\u003C!-- Rule Table End --\u003E\n\nWith text after.\n",
"meta": {
"expires": null
}
}
1 change: 1 addition & 0 deletions test/fixtures/bad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No HTML comments here.
21 changes: 21 additions & 0 deletions test/fixtures/bad/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
rules: {
foo: {
meta: {
docs: {
description: 'Foo test',
recommended: true,
},
},
},
bar: {
meta: {
docs: {
description: 'Bar test',
recommended: false,
},
},
},
bad: {},
},
};
7 changes: 7 additions & 0 deletions test/fixtures/bad/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "bad",
"version": "0.0.0",
"private": true,
"main": "index.js",
"type": "module"
}
11 changes: 11 additions & 0 deletions test/fixtures/good/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Test generation:

<!-- Rule Table Start -->
| **Rule Name** | **Description** | **Recommended** |
| :- | :- | :-: |
| [`foo`](./docs/rules/foo.md) | Foo test | yes |
| [`bar`](./docs/rules/bar.md) | Bar test | no |

<!-- Rule Table End -->

With text after.
21 changes: 21 additions & 0 deletions test/fixtures/good/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
rules: {
foo: {
meta: {
docs: {
description: 'Foo test',
recommended: true,
},
},
},
bar: {
meta: {
docs: {
description: 'Bar test',
recommended: false,
},
},
},
bad: {},
},
};
7 changes: 7 additions & 0 deletions test/fixtures/good/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "good",
"version": "0.0.0",
"private": true,
"main": "index.js",
"type": "module"
}
29 changes: 26 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
import assert from 'node:assert';
import {createRulesTable} from '../lib/index.js';
import {fileURLToPath} from 'node:url';
import fs from 'node:fs/promises';
import path from 'node:path';
import {rejects} from 'node:assert';
import snap from 'snappy-snaps';
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import test from 'node:test';

test('index', () => {
// assert.equal(foo(), 2);
const fixtures = fileURLToPath(new URL('./fixtures/', import.meta.url));
const good = path.resolve(fixtures, 'good');
const bad = path.resolve(fixtures, 'bad');

test('createRulesTable', async() => {
await createRulesTable({cwd: good});
await snap('good', await fs.readFile(path.join(good, 'README.md'), 'utf8'));
});

test('bad README', async() => {
await rejects(
() => createRulesTable({cwd: bad}),
{message: 'Invalid markdown file, needs start/end comments'}
);
});

test('bad package.json', async() => {
await rejects(
() => createRulesTable({cwd: '/'}),
{message: 'Unable to find package.json from "/"'}
);
});

0 comments on commit 1d41049

Please sign in to comment.