Skip to content
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
3 changes: 2 additions & 1 deletion packages/upgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"build": "astro-scripts build \"src/index.ts\" --bundle && tsc",
"build:ci": "astro-scripts build \"src/index.ts\" --bundle",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "astro-scripts test \"test/**/*.test.js\""
"test": "astro-scripts test \"test/**/*.test.ts\"",
"typecheck:tests": "tsc -p tsconfig.test.json"
},
"files": [
"dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os';
import { describe, it, mock } from 'node:test';
import { pathToFileURL } from 'node:url';
import { install } from '../dist/index.js';
import { setup } from './utils.js';
import { setup, type ShellFunction } from './utils.ts';

const tmpUrl = pathToFileURL(tmpdir());

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('install', () => {
prompted = true;
return { proceed: false };
},
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('install', () => {
prompted = true;
return { proceed: true };
},
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('install', () => {
prompted = true;
return { proceed: true };
},
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('install', () => {
prompted = true;
return { proceed: true };
},
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('install', () => {
});

it('npm peer dependency error retry with legacy-peer-deps', async () => {
const mockShell = mock.fn(async () => {
const mockShell = mock.fn<ShellFunction>(async () => {
if (mockShell.mock.callCount() === 0) {
// First call fails with peer dependency error
throw new Error('npm ERR! peer dependencies conflict');
Expand All @@ -230,7 +230,7 @@ describe('install', () => {
dryRun: false,
cwd: tmpUrl,
packageManager: { name: 'npm', agent: 'npm' },
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand Down Expand Up @@ -259,7 +259,7 @@ describe('install', () => {
});

it('npm non-peer dependency error does not retry', async () => {
const mockShell = mock.fn(async () => {
const mockShell = mock.fn<ShellFunction>(async () => {
throw new Error('npm ERR! some other error');
});

Expand All @@ -269,7 +269,7 @@ describe('install', () => {
dryRun: false,
cwd: tmpUrl,
packageManager: { name: 'npm', agent: 'npm' },
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand All @@ -290,7 +290,7 @@ describe('install', () => {
});

it('npm peer dependency error retry fails on second attempt', async () => {
const mockShell = mock.fn(async () => {
const mockShell = mock.fn<ShellFunction>(async () => {
// Both calls fail with peer dependency errors
throw new Error('npm ERR! peer dependencies conflict');
});
Expand All @@ -301,7 +301,7 @@ describe('install', () => {
dryRun: false,
cwd: tmpUrl,
packageManager: { name: 'npm', agent: 'npm' },
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('install', () => {
});

it('pnpm peer dependency error does not retry', async () => {
const mockShell = mock.fn(async () => {
const mockShell = mock.fn<ShellFunction>(async () => {
throw new Error('pnpm ERR! peer dependencies conflict');
});

Expand All @@ -341,7 +341,7 @@ describe('install', () => {
dryRun: false,
cwd: tmpUrl,
packageManager: { name: 'pnpm', agent: 'pnpm' },
exit: (code) => {
exit: (code: number) => {
exitCode = code;
},
packages: [
Expand Down
15 changes: 12 additions & 3 deletions packages/upgrade/test/utils.js → packages/upgrade/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ import { before, beforeEach } from 'node:test';
import { stripVTControlCharacters } from 'node:util';
import { setStdout } from '../dist/index.js';

export type ShellFunction = (
command: string,
flags: string[],
) => Promise<{
stdout: string;
stderr: string;
exitCode: number;
}>;

export function setup() {
const ctx = { messages: [] };
const ctx: { messages: string[] } = { messages: [] };
before(() => {
setStdout(
Object.assign({}, process.stdout, {
write(buf) {
write(buf: string | Uint8Array) {
ctx.messages.push(stripVTControlCharacters(String(buf)).trim());
return true;
},
Expand All @@ -25,7 +34,7 @@ export function setup() {
length() {
return ctx.messages.length;
},
hasMessage(content) {
hasMessage(content: string) {
return !!ctx.messages.find((msg) => msg.includes(content));
},
};
Expand Down
13 changes: 13 additions & 0 deletions packages/upgrade/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"include": ["test/**/*.ts"],
"exclude": ["test/fixtures/**"],
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"rewriteRelativeImportExtensions": true
},
"references": [{ "path": "../astro/tsconfig.test.json" }]
}
105 changes: 0 additions & 105 deletions pnpm-lock.yaml

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

Loading