-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sk-inf-674-changesets' into sk-inf-674-changesets-test
- Loading branch information
Showing
3 changed files
with
166 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
packages/create-audius-app/tests/integration/create-audius-app.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
168
packages/create-audius-app/tests/integration/create-audius-app.ts
This file was deleted.
Oops, something went wrong.