Skip to content
Open
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
19 changes: 15 additions & 4 deletions packages/create/tests/create-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { resolve } from 'node:path'
import { createApp } from '../src/create-app.js'

import { createMemoryEnvironment } from '../src/environment.js'
import type { AddOn, Options } from '../src/types.js'
import type { AddOn, Options, Starter } from '../src/types.js'

function toPosixPath(path: string) {
return path.replace(/\\/g, '/').replace(/^[A-Z]:/i, '')
}

const simpleOptions = {
projectName: 'test',
Expand Down Expand Up @@ -63,9 +67,16 @@ describe('createApp', () => {

const cwd = process.cwd()

expect(output.files[resolve(cwd, '/foo/bar/baz/src/test.txt')]).toEqual(
'Hello',
const normalizedFiles = Object.fromEntries(
Object.entries(output.files).map(([path, contents]) => [
toPosixPath(path),
contents,
]),
)

expect(
normalizedFiles[toPosixPath(resolve(cwd, '/foo/bar/baz/src/test.txt'))],
).toEqual('Hello')
})

it('should create an app - with a starter', async () => {
Expand All @@ -80,7 +91,7 @@ describe('createApp', () => {
getFiles: () => ['src/test2.txt'],
getFileContents: () => 'Hello-2',
getDeletedFiles: () => [],
} as unknown as AddOn,
} as unknown as Starter,
})

expect(output.files['/src/test2.txt']).toEqual('Hello-2')
Expand Down
6 changes: 5 additions & 1 deletion packages/create/tests/file-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
vi.mock('node:fs', () => fs)
vi.mock('node:fs/promises', () => fs.promises)

function toPosixPath(path: string) {
return path.replace(/\\/g, '/').replace(/^[A-Z]:/i, '')
}

beforeEach(() => {
vol.reset()
})
Expand Down Expand Up @@ -138,7 +142,7 @@ describe('findFilesRecursively', () => {
const files = {}
findFilesRecursively('/src', files)

expect(Object.keys(files)).toEqual([
expect(Object.keys(files).map(toPosixPath)).toEqual([
'/src/subdir/subdir2/test.txt',
'/src/subdir/test.txt',
'/src/test.txt',
Expand Down