Skip to content

Commit aff9339

Browse files
authored
chore(test): organize test folders (#307)
* chore(test): organize test folders * fixup!
1 parent 42bbad6 commit aff9339

32 files changed

+124
-105
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Tests files
2-
src/generators/api-links/test/fixtures/
2+
src/generators/api-links/__tests__/fixtures/
33
*.snapshot

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default [
77
pluginJs.configs.recommended,
88
importX.flatConfigs.recommended,
99
{
10-
ignores: ['out/', 'src/generators/api-links/test/fixtures/'],
10+
ignores: ['out/', 'src/generators/api-links/__tests__/fixtures/'],
1111
},
1212
{
1313
files: ['**/*.mjs'],
File renamed without changes.

src/generators/jsx-ast/test/utils.test.mjs

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import { AST_NODE_TYPES } from '../../constants.mjs';
5+
import { createJSXElement } from '../ast.mjs';
6+
7+
describe('AST utilities', () => {
8+
it('should build correct JSX tree with createJSXElement', () => {
9+
const el = createJSXElement('TestComponent', {
10+
inline: false,
11+
children: 'Some content',
12+
dataAttr: { test: true },
13+
});
14+
15+
assert.equal(el.type, AST_NODE_TYPES.MDX.JSX_BLOCK_ELEMENT);
16+
assert.equal(el.name, 'TestComponent');
17+
assert.ok(Array.isArray(el.children));
18+
assert.ok(el.attributes.some(attr => attr.name === 'dataAttr'));
19+
});
20+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import { SAMPLE } from './utils.mjs';
5+
import { buildSideBarDocPages, buildMetaBarProps } from '../buildBarProps.mjs';
6+
7+
describe('buildBarProps utilities', () => {
8+
describe('buildSideBarDocPages', () => {
9+
it('should return expected format', () => {
10+
const grouped = new Map([['sample-api', [SAMPLE]]]);
11+
const result = buildSideBarDocPages(grouped, [SAMPLE]);
12+
13+
assert.equal(result.length, 1);
14+
assert.equal(result[0].title, 'SampleFunc');
15+
assert.equal(result[0].doc, 'sample-api.html');
16+
assert.deepEqual(result[0].headings, [['SampleFunc', '#sample-func']]);
17+
});
18+
});
19+
20+
describe('buildMetaBarProps', () => {
21+
it('should include expected fields', () => {
22+
const result = buildMetaBarProps(SAMPLE, [SAMPLE]);
23+
24+
assert.equal(result.addedIn, 'v1.0.0');
25+
assert.deepEqual(result.viewAs, [['JSON', 'sample-api.json']]);
26+
assert.ok(result.readingTime.startsWith('1 min'));
27+
assert.ok(result.editThisPage.endsWith('sample-api.md'));
28+
assert.deepEqual(result.headings, [{ depth: 2, value: 'SampleFunc' }]);
29+
});
30+
});
31+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import remarkParse from 'remark-parse';
5+
import remarkStringify from 'remark-stringify';
6+
import { unified } from 'unified';
7+
8+
import { SAMPLE } from './utils.mjs';
9+
import { AST_NODE_TYPES } from '../../constants.mjs';
10+
import buildContent from '../buildContent.mjs';
11+
12+
describe('buildContent', () => {
13+
it('should process entries and include JSX wrapper elements', () => {
14+
const processor = unified().use(remarkParse).use(remarkStringify);
15+
const tree = buildContent([SAMPLE], SAMPLE, {}, processor);
16+
17+
const article = tree.children.find(
18+
child => child.name === AST_NODE_TYPES.JSX.ARTICLE
19+
);
20+
assert.ok(article);
21+
assert.ok(
22+
article.children.some(c => c.name === AST_NODE_TYPES.JSX.SIDE_BAR)
23+
);
24+
assert.ok(article.children.some(c => c.name === AST_NODE_TYPES.JSX.FOOTER));
25+
});
26+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const SAMPLE = {
2+
api: 'sample-api',
3+
heading: {
4+
depth: 2,
5+
data: { name: 'SampleFunc', slug: 'sample-func', type: 'function' },
6+
},
7+
content: {
8+
type: 'root',
9+
children: [
10+
{ type: 'text', value: 'Example text for testing reading time.' },
11+
],
12+
},
13+
added_in: 'v1.0.0',
14+
source_link: '/src/index.js',
15+
changes: [
16+
{
17+
version: 'v1.1.0',
18+
description: 'Improved performance',
19+
'pr-url': 'https://github.com/org/repo/pull/123',
20+
},
21+
],
22+
};

src/test/man-page.test.mjs renamed to src/generators/man-page/utils/__tests__/converter.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
flagValueToMandoc,
99
convertOptionToMandoc,
1010
convertEnvVarToMandoc,
11-
} from '../generators/man-page/utils/converter.mjs';
11+
} from '../converter.mjs';
1212

1313
const textNode = text => u('text', text);
1414

File renamed without changes.

src/linter/tests/reporters/console.test.mjs renamed to src/linter/reporters/__tests__/console.test.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import assert from 'node:assert';
1+
import assert from 'node:assert/strict';
22
import { describe, it } from 'node:test';
33

4-
import reporter from '../../reporters/console.mjs';
5-
import { errorIssue, infoIssue, warnIssue } from '../fixtures/issues.mjs';
4+
import {
5+
errorIssue,
6+
infoIssue,
7+
warnIssue,
8+
} from '../../__tests__/fixtures/issues.mjs';
9+
import reporter from '../console.mjs';
610

711
const testCases = [
812
{
@@ -30,8 +34,8 @@ describe('console', () => {
3034

3135
reporter(issue);
3236

33-
assert.strictEqual(mock.callCount(), 1);
34-
assert.deepStrictEqual(mock.calls[0].arguments, [expected]);
37+
assert.equal(mock.callCount(), 1);
38+
assert.deepEqual(mock.calls[0].arguments, [expected]);
3539
});
3640
});
3741
});
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import assert from 'node:assert';
1+
import assert from 'node:assert/strict';
22
import { describe, it } from 'node:test';
33

4-
import github from '../../reporters/github.mjs';
5-
import { errorIssue, infoIssue, warnIssue } from '../fixtures/issues.mjs';
4+
import * as issues from '../../__tests__/fixtures/issues.mjs';
5+
import github from '../github.mjs';
66

77
describe('github', () => {
88
it('should write to stdout with the correct fn based on the issue level', t => {
99
t.mock.method(process.stdout, 'write');
1010

11-
github(infoIssue);
12-
github(warnIssue);
13-
github(errorIssue);
11+
Object.values(issues).forEach(github);
1412

15-
assert.strictEqual(process.stdout.write.mock.callCount(), 3);
13+
assert.equal(process.stdout.write.mock.callCount(), 3);
1614

1715
const callsArgs = process.stdout.write.mock.calls.map(call =>
1816
call.arguments[0].trim()
1917
);
2018

21-
assert.deepStrictEqual(callsArgs, [
19+
assert.deepEqual(callsArgs, [
20+
'::error file=doc/api/test.md,line=1,endLine=1::This is a ERROR issue',
2221
'::notice file=doc/api/test.md,line=1,endLine=1::This is a INFO issue',
2322
'::warning file=doc/api/test.md,line=1,endLine=1::This is a WARN issue',
24-
'::error file=doc/api/test.md,line=1,endLine=1::This is a ERROR issue',
2523
]);
2624
});
2725
});

src/linter/tests/rules/duplicate-stability-nodes.test.mjs renamed to src/linter/rules/__tests__/duplicate-stability-nodes.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { deepStrictEqual, strictEqual } from 'node:assert';
22
import { describe, it, mock } from 'node:test';
33

44
import { LINT_MESSAGES } from '../../constants.mjs';
5-
import { duplicateStabilityNodes } from '../../rules/duplicate-stability-nodes.mjs';
5+
import { duplicateStabilityNodes } from '../duplicate-stability-nodes.mjs';
66

77
// Mock data structure for creating test entries
88
const createStabilityNode = (value, line = 1, column = 1) => ({

src/linter/tests/fixtures/invalidChangeVersion-environment.mjs renamed to src/linter/rules/__tests__/fixtures/invalid-change-version-subprocess.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mock } from 'node:test';
33

44
import dedent from 'dedent';
55

6-
import { invalidChangeVersion } from '../../rules/invalid-change-version.mjs';
6+
import { invalidChangeVersion } from '../../invalid-change-version.mjs';
77

88
const yamlContent = dedent`
99
<!-- YAML

src/linter/tests/rules/invalid-change-version.test.mjs renamed to src/linter/rules/__tests__/invalid-change-version.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
66

77
import dedent from 'dedent';
88

9-
import { invalidChangeVersion } from '../../rules/invalid-change-version.mjs';
9+
import { invalidChangeVersion } from '../invalid-change-version.mjs';
1010

1111
describe('invalidChangeVersion', () => {
1212
it('should not report if all change versions are non-empty', () => {
@@ -92,7 +92,7 @@ changes:
9292
[
9393
fileURLToPath(
9494
new URL(
95-
'../fixtures/invalidChangeVersion-environment.mjs',
95+
'./fixtures/invalid-change-version-subprocess.mjs',
9696
import.meta.url
9797
)
9898
),
File renamed without changes.

src/utils/tests/parser.test.mjs renamed to src/utils/parser/__tests__/index.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
transformTypeToReferenceLink,
77
parseHeadingIntoMetadata,
88
normalizeYamlSyntax,
9-
} from '../parser/index.mjs';
9+
} from '../index.mjs';
1010

1111
describe('transformTypeToReferenceLink', () => {
1212
it('should transform a JavaScript primitive type into a Markdown link', () => {

src/utils/tests/queries.test.mjs renamed to src/utils/queries/__tests__/index.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { strictEqual, deepStrictEqual } from 'node:assert';
22
import { describe, it } from 'node:test';
33

4-
import createQueries from '../queries/index.mjs';
4+
import createQueries from '../index.mjs';
55

66
describe('createQueries', () => {
77
it('should add YAML metadata correctly', () => {

0 commit comments

Comments
 (0)