Skip to content

Commit

Permalink
Merge branch 'sk-inf-674-changesets' into sk-inf-674-changesets-test
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptype committed Apr 11, 2024
2 parents e5df8bd + cb587a6 commit 24a9357
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 169 deletions.
1 change: 0 additions & 1 deletion packages/create-audius-app/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
import { cyan, green, red, bold } from 'picocolors'
import Commander from 'commander'
import path from 'path'
Expand Down
166 changes: 166 additions & 0 deletions packages/create-audius-app/tests/integration/create-audius-app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import execa from 'execa'
import fs from 'fs-extra'
import path from 'path'
import { useTempDir } from './use-temp-dir'
import { describe, it, expect } from 'vitest'
import { projectFilesShouldExist, projectFilesShouldNotExist } from './utils'

const cli = require.resolve('create-audius-app/dist/index.js')

const run = (args: string[], options: execa.Options) => {
return execa('node', [cli].concat(args), {
...options,
env: {
...(options.env || {})
} as any
})
}

describe('create audius app', () => {
it('non-empty directory', async () => {
await useTempDir(async (cwd) => {
const projectName = 'non-empty-directory'
await fs.mkdirp(path.join(cwd, projectName))
const pkg = path.join(cwd, projectName, 'package.json')
fs.writeFileSync(pkg, '{ "foo": "bar" }')

const res = await run([projectName], {
cwd,
reject: false
})
expect(res.exitCode).toBe(1)
expect(res.stdout).toMatch(/contains files that could conflict/)
})
})

it('empty directory', async () => {
await useTempDir(async (cwd) => {
const projectName = 'empty-directory'
const res = await run([projectName], { cwd })

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files: ['package.json', 'src/App.tsx', '.gitignore']
})
})
})

it('invalid example name', async () => {
await useTempDir(async (cwd) => {
const projectName = 'invalid-example-name'
const res = await run([projectName, '--example', 'not a real example'], {
cwd,
reject: false
})

expect(res.exitCode).toBe(1)
projectFilesShouldNotExist({
cwd,
projectName,
files: ['package.json']
})
})
})

it('valid example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'valid-example'
const res = await run([projectName, '--example', 'react'], {
cwd
})

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files: ['package.json', 'src/App.tsx', '.gitignore']
})
})
})

it('should fall back to default template', async () => {
await useTempDir(async (cwd) => {
const projectName = 'fail-example'
const res = await run([projectName], {
cwd,
input: '\n'
})

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files: ['package.json', 'src/App.tsx', '.gitignore']
})
})
})

it('should exit if the folder is not writable', async () => {
await useTempDir(async (cwd) => {
const projectName = 'not-writable'

// if the folder isn't able to be write restricted we can't test
// this so skip
if (
await fs
.writeFile(path.join(cwd, 'test'), 'hello')
.then(() => true)
.catch(() => false)
) {
console.warn(
`Test folder is not write restricted skipping write permission test`
)
return
}
const res = await run([projectName], {
cwd,
reject: false
})

expect(res.stderr).toMatch(
/you do not have write permissions for this folder/
)
expect(res.exitCode).toBe(1)
}, 0o500)
})

it('should create a project in the current directory', async () => {
await useTempDir(async (cwd) => {
const env = { ...process.env }

const res = await run(['.'], {
cwd,
env,
extendEnv: false,
stdio: 'inherit'
})

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
files: ['package.json', 'src/App.tsx', '.gitignore']
})
})
})

it('should ask the user for a name for the project if none supplied', async () => {
await useTempDir(async (cwd) => {
const projectName = 'my-app'
const res = await run([], {
cwd,
input: `${projectName}\n`
})

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName: 'my-app',
files: ['package.json', 'src/App.tsx', '.gitignore']
})
})
})
})

describe('test', () => {})
168 changes: 0 additions & 168 deletions packages/create-audius-app/tests/integration/create-audius-app.ts

This file was deleted.

0 comments on commit 24a9357

Please sign in to comment.