Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build
lib
/node_modules
coverage
test/tmp
78 changes: 57 additions & 21 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions test/components/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import fs from 'node:fs';
import os from 'node:os';
import pathe from 'pathe';
import ts from 'typescript';
import { documentComponents, DocumenterOptions } from '../../src/components';
Expand All @@ -15,7 +14,9 @@ export function buildProject(name: string, options?: Partial<DocumenterOptions>)
}

export function getTemporaryDir() {
return fs.mkdtempSync(pathe.join(os.tmpdir(), 'documenter-'));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vite 6.4.2 blocks access to files outside the project root, which broke tests that write output to the OS temp. To fix this, we can either move the output directory into the project directory, or explicitly allowlist the temp path to restore the previous behavior. I prefer the first option, as it avoids broadening file system access unnecessarily and aligns with the principle of least privilege.

const tmpBase = pathe.resolve('test/tmp');
fs.mkdirSync(tmpBase, { recursive: true });
return fs.mkdtempSync(pathe.join(tmpBase, 'documenter-'));
}

export function getInMemoryProject(source: string) {
Expand Down
2 changes: 1 addition & 1 deletion test/components/writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ test('should write documentation files into the outDir', async () => {
simple: expect.objectContaining({ name: 'Simple', dashCaseName: 'simple' }),
});
expect(() => execSync('tsc index.d.ts', { cwd: outDir, stdio: 'inherit' })).not.toThrow();
});
}, 60_000);
9 changes: 9 additions & 0 deletions test/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import fs from 'node:fs';
import pathe from 'pathe';

export function setup() {
const tmpDir = pathe.resolve('test/tmp');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will run before starting a test to clean up temporary files.

fs.rmSync(tmpDir, { recursive: true, force: true });
}
2 changes: 1 addition & 1 deletion test/test-utils/writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ test('should write documentation files into the outDir', async () => {
classes: [expect.objectContaining({ name: 'TestUtilWrapper' })],
});
expect(() => execSync('tsc dom.d.ts selectors.d.ts', { cwd: outDir, stdio: 'inherit' })).not.toThrow();
});
}, 60_000);
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globalSetup: ['test/global-setup.ts'],
testTimeout: 15000,
coverage: {
enabled: process.env.CI === 'true',
Expand Down
Loading