Skip to content

chore(test): organize test folders #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Tests files
src/generators/api-links/test/fixtures/
src/generators/api-links/__tests__/fixtures/
*.snapshot
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pluginJs.configs.recommended,
importX.flatConfigs.recommended,
{
ignores: ['out/', 'src/generators/api-links/test/fixtures/'],
ignores: ['out/', 'src/generators/api-links/__tests__/fixtures/'],

Check warning on line 10 in eslint.config.mjs

View check run for this annotation

Codecov / codecov/patch

eslint.config.mjs#L10

Added line #L10 was not covered by tests
},
{
files: ['**/*.mjs'],
Expand Down
File renamed without changes.
82 changes: 0 additions & 82 deletions src/generators/jsx-ast/test/utils.test.mjs

This file was deleted.

20 changes: 20 additions & 0 deletions src/generators/jsx-ast/utils/__tests__/ast.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import { AST_NODE_TYPES } from '../../constants.mjs';
import { createJSXElement } from '../ast.mjs';

describe('AST utilities', () => {
it('should build correct JSX tree with createJSXElement', () => {
const el = createJSXElement('TestComponent', {
inline: false,
children: 'Some content',
dataAttr: { test: true },
});

assert.equal(el.type, AST_NODE_TYPES.MDX.JSX_BLOCK_ELEMENT);
assert.equal(el.name, 'TestComponent');
assert.ok(Array.isArray(el.children));
assert.ok(el.attributes.some(attr => attr.name === 'dataAttr'));
});
});
31 changes: 31 additions & 0 deletions src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import { SAMPLE } from './utils.mjs';
import { buildSideBarDocPages, buildMetaBarProps } from '../buildBarProps.mjs';

describe('buildBarProps utilities', () => {
describe('buildSideBarDocPages', () => {
it('should return expected format', () => {
const grouped = new Map([['sample-api', [SAMPLE]]]);
const result = buildSideBarDocPages(grouped, [SAMPLE]);

assert.equal(result.length, 1);
assert.equal(result[0].title, 'SampleFunc');
assert.equal(result[0].doc, 'sample-api.html');
assert.deepEqual(result[0].headings, [['SampleFunc', '#sample-func']]);
});
});

describe('buildMetaBarProps', () => {
it('should include expected fields', () => {
const result = buildMetaBarProps(SAMPLE, [SAMPLE]);

assert.equal(result.addedIn, 'v1.0.0');
assert.deepEqual(result.viewAs, [['JSON', 'sample-api.json']]);
assert.ok(result.readingTime.startsWith('1 min'));
assert.ok(result.editThisPage.endsWith('sample-api.md'));
assert.deepEqual(result.headings, [{ depth: 2, value: 'SampleFunc' }]);
});
});
});
26 changes: 26 additions & 0 deletions src/generators/jsx-ast/utils/__tests__/buildContent.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import { unified } from 'unified';

import { SAMPLE } from './utils.mjs';
import { AST_NODE_TYPES } from '../../constants.mjs';
import buildContent from '../buildContent.mjs';

describe('buildContent', () => {
it('should process entries and include JSX wrapper elements', () => {
const processor = unified().use(remarkParse).use(remarkStringify);
const tree = buildContent([SAMPLE], SAMPLE, {}, processor);

const article = tree.children.find(
child => child.name === AST_NODE_TYPES.JSX.ARTICLE
);
assert.ok(article);
assert.ok(
article.children.some(c => c.name === AST_NODE_TYPES.JSX.SIDE_BAR)
);
assert.ok(article.children.some(c => c.name === AST_NODE_TYPES.JSX.FOOTER));
});
});
22 changes: 22 additions & 0 deletions src/generators/jsx-ast/utils/__tests__/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const SAMPLE = {
api: 'sample-api',
heading: {
depth: 2,
data: { name: 'SampleFunc', slug: 'sample-func', type: 'function' },
},
content: {
type: 'root',
children: [
{ type: 'text', value: 'Example text for testing reading time.' },
],
},
added_in: 'v1.0.0',
source_link: '/src/index.js',
changes: [
{
version: 'v1.1.0',
description: 'Improved performance',
'pr-url': 'https://github.com/org/repo/pull/123',
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
flagValueToMandoc,
convertOptionToMandoc,
convertEnvVarToMandoc,
} from '../generators/man-page/utils/converter.mjs';
} from '../converter.mjs';

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

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import reporter from '../../reporters/console.mjs';
import { errorIssue, infoIssue, warnIssue } from '../fixtures/issues.mjs';
import {
errorIssue,
infoIssue,
warnIssue,
} from '../../__tests__/fixtures/issues.mjs';
import reporter from '../console.mjs';

const testCases = [
{
Expand Down Expand Up @@ -30,8 +34,8 @@ describe('console', () => {

reporter(issue);

assert.strictEqual(mock.callCount(), 1);
assert.deepStrictEqual(mock.calls[0].arguments, [expected]);
assert.equal(mock.callCount(), 1);
assert.deepEqual(mock.calls[0].arguments, [expected]);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

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

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

github(infoIssue);
github(warnIssue);
github(errorIssue);
Object.values(issues).forEach(github);

assert.strictEqual(process.stdout.write.mock.callCount(), 3);
assert.equal(process.stdout.write.mock.callCount(), 3);

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

assert.deepStrictEqual(callsArgs, [
assert.deepEqual(callsArgs, [
'::error file=doc/api/test.md,line=1,endLine=1::This is a ERROR issue',
'::notice file=doc/api/test.md,line=1,endLine=1::This is a INFO issue',
'::warning file=doc/api/test.md,line=1,endLine=1::This is a WARN issue',
'::error file=doc/api/test.md,line=1,endLine=1::This is a ERROR issue',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { deepStrictEqual, strictEqual } from 'node:assert';
import { describe, it, mock } from 'node:test';

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

// Mock data structure for creating test entries
const createStabilityNode = (value, line = 1, column = 1) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mock } from 'node:test';

import dedent from 'dedent';

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

const yamlContent = dedent`
<!-- YAML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';

import dedent from 'dedent';

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

describe('invalidChangeVersion', () => {
it('should not report if all change versions are non-empty', () => {
Expand Down Expand Up @@ -92,7 +92,7 @@ changes:
[
fileURLToPath(
new URL(
'../fixtures/invalidChangeVersion-environment.mjs',
'./fixtures/invalid-change-version-subprocess.mjs',
import.meta.url
)
),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
transformTypeToReferenceLink,
parseHeadingIntoMetadata,
normalizeYamlSyntax,
} from '../parser/index.mjs';
} from '../index.mjs';

describe('transformTypeToReferenceLink', () => {
it('should transform a JavaScript primitive type into a Markdown link', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strictEqual, deepStrictEqual } from 'node:assert';
import { describe, it } from 'node:test';

import createQueries from '../queries/index.mjs';
import createQueries from '../index.mjs';

describe('createQueries', () => {
it('should add YAML metadata correctly', () => {
Expand Down
Loading