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
1 change: 0 additions & 1 deletion packages/astro-rss/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"include": ["test/**/*.ts"],
"exclude": ["test/fixtures/**"],
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
Expand Down
3 changes: 2 additions & 1 deletion packages/create-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 --build tsconfig.test.json"
},
"files": [
"dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ describe('context', () => {
});

it('--add with --no-install conflicts', async () => {
const exitCode = await new Promise((resolve) => {
const originalExit = process.exit;
process.exit = (code) => {
process.exit = originalExit;
resolve(code);
};
getContext(['--add', 'cloudflare', '--no-install']);
});
const originalExit = process.exit;
let exitCode: number | string | null | undefined;
const patchedExit: typeof originalExit = (code) => {
exitCode = code;
throw code;
};
process.exit = patchedExit;
try {
await getContext(['--add', 'cloudflare', '--no-install']);
} catch {
// expected: patchedExit throws to unwind getContext
} finally {
process.exit = originalExit;
}
assert.equal(exitCode, 1);
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { dependencies } from '../dist/index.js';
import { setup } from './utils.js';
import { type DependenciesContext, mockPrompt, setup } from './utils.ts';

describe('dependencies', () => {
const fixture = setup();

it('--yes', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
yes: true,
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
prompt: mockPrompt({ deps: true }),
tasks: [],
};

await dependencies(context);
Expand All @@ -21,13 +22,14 @@ describe('dependencies', () => {
});

it('--yes with third-party template warns', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
yes: true,
template: 'github:someone/starter',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
prompt: mockPrompt({ deps: true }),
tasks: [],
};

await dependencies(context);
Expand All @@ -36,13 +38,14 @@ describe('dependencies', () => {
});

it('starlight templates do not warn', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
yes: true,
template: 'starlight/tailwind',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
prompt: mockPrompt({ deps: true }),
tasks: [],
};

await dependencies(context);
Expand All @@ -51,13 +54,14 @@ describe('dependencies', () => {
});

it('starlight-prefixed third-party templates warn', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
yes: true,
template: 'starlightevil/foo',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
prompt: mockPrompt({ deps: true }),
tasks: [],
};

await dependencies(context);
Expand All @@ -66,13 +70,14 @@ describe('dependencies', () => {
});

it('warns without --yes when install is enabled', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
install: true,
template: 'github:someone/starter',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
prompt: mockPrompt({ deps: true }),
tasks: [],
};

await dependencies(context);
Expand All @@ -81,12 +86,13 @@ describe('dependencies', () => {
});

it('prompt yes', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
prompt: mockPrompt({ deps: true }),
install: undefined,
tasks: [],
};

await dependencies(context);
Expand All @@ -96,12 +102,13 @@ describe('dependencies', () => {
});

it('prompt no', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: false }),
prompt: mockPrompt({ deps: false }),
install: undefined,
tasks: [],
};

await dependencies(context);
Expand All @@ -111,25 +118,27 @@ describe('dependencies', () => {
});

it('--install', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
install: true,
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: false }),
prompt: mockPrompt({ deps: false }),
tasks: [],
};
await dependencies(context);
assert.ok(fixture.hasMessage('Skipping dependency installation'));
assert.equal(context.install, true);
});

it('--no-install ', async () => {
const context = {
const context: DependenciesContext = {
cwd: '',
install: false,
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: false }),
prompt: mockPrompt({ deps: false }),
tasks: [],
};

await dependencies(context);
Expand All @@ -140,17 +149,20 @@ describe('dependencies', () => {

describe('--add', async () => {
it('fails for non-supported integration', async () => {
let context = {
let context: DependenciesContext = {
cwd: '',
add: ['foo '],
dryRun: true,
prompt: () => ({ deps: false }),
prompt: mockPrompt({ deps: false }),
packageManager: 'npm',
tasks: [],
};

try {
await dependencies(context);
assert.fail('The function should throw an error');
} catch (error) {
assert.ok(error instanceof Error);
assert.ok(
error.message.includes('Invalid package name "foo "'),
`Expected error about invalid package name, got: ${error.message}`,
Expand All @@ -160,13 +172,16 @@ describe('dependencies', () => {
cwd: '',
add: ['react', 'bar lorem'],
dryRun: true,
prompt: () => ({ deps: false }),
prompt: mockPrompt({ deps: false }),
packageManager: 'npm',
tasks: [],
};

try {
await dependencies(context);
assert.fail('The function should throw an error');
} catch (error) {
assert.ok(error instanceof Error);
assert.ok(
error.message.includes('Invalid package name "bar lorem"'),
`Expected error about invalid package name, got: ${error.message}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,41 @@ import { mkdir, writeFile } from 'node:fs/promises';
import { after, before, describe, it } from 'node:test';

import { git } from '../dist/index.js';
import { setup } from './utils.js';
import { type GitContext, mockPrompt, setup } from './utils.ts';

describe('git', () => {
const fixture = setup();

it('none', async () => {
const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
const context: GitContext = {
cwd: '',
dryRun: true,
prompt: mockPrompt({ git: false }),
tasks: [],
};
await git(context);

assert.ok(fixture.hasMessage('Skipping Git initialization'));
});

it('yes (--dry-run)', async () => {
const context = { cwd: '', dryRun: true, prompt: () => ({ git: true }) };
const context: GitContext = {
cwd: '',
dryRun: true,
prompt: mockPrompt({ git: true }),
tasks: [],
};
await git(context);
assert.ok(fixture.hasMessage('Skipping Git initialization'));
});

it('no (--dry-run)', async () => {
const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
const context: GitContext = {
cwd: '',
dryRun: true,
prompt: mockPrompt({ git: false }),
tasks: [],
};
await git(context);

assert.ok(fixture.hasMessage('Skipping Git initialization'));
Expand All @@ -40,11 +55,12 @@ describe('git initialized', () => {
});

it('already initialized', async () => {
const context = {
const context: GitContext = {
git: true,
cwd: './test/fixtures/not-empty',
dryRun: false,
prompt: () => ({ git: false }),
prompt: mockPrompt({ git: false }),
tasks: [],
};
await git(context);

Expand Down
Loading
Loading