Skip to content

Commit

Permalink
Add tests to --add
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOtterlord committed Sep 27, 2024
1 parent 892dfc6 commit e80dfb8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/create-astro/src/actions/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export async function dependencies(
ctx.install = deps;
}

ctx.add = ctx.add?.reduce<string[]>((acc, item) => acc.concat(item.split(',')), []);

if (ctx.dryRun) {
await info('--dry-run', `Skipping dependency installation`);
await info('--dry-run', `Skipping dependency installation${ ctx.add ? ` and adding ${ctx.add.join(', ')}` : '' }`);
} else if (deps) {
ctx.tasks.push({
pending: 'Dependencies',
Expand Down Expand Up @@ -63,7 +65,6 @@ export async function dependencies(
}
}

add = add?.reduce<string[]>((acc, item) => acc.concat(item.split(',')), []);
if (add) {
ctx.tasks.push({
pending: 'Integrations',
Expand Down
60 changes: 60 additions & 0 deletions packages/create-astro/test/integrations.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { dependencies } from '../dist/index.js';
import { setup } from './utils.js';
describe('integrations', () => {
const fixture = setup();

it('--add node', async () => {
const context = {
cwd: '',
yes: true,
packageManager: 'npm',
dryRun: true,
add: ['node'],
};

await dependencies(context);

assert.ok(fixture.hasMessage('--dry-run Skipping dependency installation and adding node'));
});

it('--add node --add react', async () => {
const context = {
cwd: '',
yes: true,
packageManager: 'npm',
dryRun: true,
add: ['node', 'react'],
};

await dependencies(context);

assert.ok(fixture.hasMessage('--dry-run Skipping dependency installation and adding node, react'));
});

it('--add node,react', async () => {
const context = {
cwd: '',
yes: true,
packageManager: 'npm',
dryRun: true,
add: ['node,react']
};

await dependencies(context);

assert.ok(fixture.hasMessage('--dry-run Skipping dependency installation and adding node, react'));
});

it('-y', async () => {
const context = {
cwd: '',
yes: true,
packageManager: 'npm',
dryRun: true,
};
await dependencies(context);
assert.ok(fixture.hasMessage('--dry-run Skipping dependency installation'));
});
});

0 comments on commit e80dfb8

Please sign in to comment.