-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize tests in to multiple files so the tests are less overwhelm…
…ing to work with
- Loading branch information
1 parent
f793715
commit be0bbe3
Showing
9 changed files
with
602 additions
and
537 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
import { assertGeneratedCorrectly } from '../assertions.js'; | ||
import { createAddon, createTmp, install, runScript } from '../utils.js'; | ||
|
||
describe('--addon-location', () => { | ||
let cwd = ''; | ||
let tmpDir = ''; | ||
let addonLocation = 'packages/my-custom-location'; | ||
|
||
beforeAll(async () => { | ||
tmpDir = await createTmp(); | ||
|
||
let { name } = await createAddon({ | ||
args: [`--addon-location=${addonLocation}`, '--pnpm=true'], | ||
options: { cwd: tmpDir }, | ||
}); | ||
|
||
cwd = path.join(tmpDir, name); | ||
|
||
await install({ cwd, packageManager: 'pnpm' }); | ||
}); | ||
|
||
afterAll(async () => { | ||
fs.rm(tmpDir, { recursive: true, force: true }); | ||
}); | ||
|
||
it('was generated correctly', async () => { | ||
assertGeneratedCorrectly({ projectRoot: cwd, addonLocation }); | ||
}); | ||
|
||
it('runs tests', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'test', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
it('lints all pass', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
}); |
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,49 @@ | ||
import fse from 'fs-extra'; | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
import { createAddon, createTmp, install, runScript } from '../utils.js'; | ||
|
||
describe('--addon-only', () => { | ||
let cwd = ''; | ||
let tmpDir = ''; | ||
|
||
beforeAll(async () => { | ||
tmpDir = await createTmp(); | ||
|
||
let { name } = await createAddon({ | ||
args: ['--addon-only', '--pnpm=true'], | ||
options: { cwd: tmpDir }, | ||
}); | ||
|
||
cwd = path.join(tmpDir, name); | ||
|
||
await install({ cwd, packageManager: 'pnpm' }); | ||
}); | ||
|
||
afterAll(async () => { | ||
fs.rm(tmpDir, { recursive: true, force: true }); | ||
}); | ||
|
||
it('is not a monorepo', async () => { | ||
let hasPnpmWorkspace = await fse.pathExists(path.join(cwd, 'pnpm-workspace.yaml')); | ||
let packageJson = await fse.readJson(path.join(cwd, 'package.json')); | ||
|
||
expect(hasPnpmWorkspace).toBe(false); | ||
// Pnpm doesn't use this field, but it's good that it doesn't exist. | ||
expect(packageJson.workspaces).toBeFalsy(); | ||
}); | ||
|
||
it('can build', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'build', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
it('has passing lints', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
}); |
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,45 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
import { assertGeneratedCorrectly } from '../assertions.js'; | ||
import { createAddon, createTmp, install, runScript } from '../utils.js'; | ||
|
||
describe('--test-app-location', () => { | ||
let cwd = ''; | ||
let tmpDir = ''; | ||
let testAppLocation = 'packages/my-custom-location'; | ||
|
||
beforeAll(async () => { | ||
tmpDir = await createTmp(); | ||
|
||
let { name } = await createAddon({ | ||
args: [`--test-app-location=${testAppLocation}`, '--pnpm=true'], | ||
options: { cwd: tmpDir }, | ||
}); | ||
|
||
cwd = path.join(tmpDir, name); | ||
|
||
await install({ cwd, packageManager: 'pnpm' }); | ||
}); | ||
|
||
afterAll(async () => { | ||
fs.rm(tmpDir, { recursive: true, force: true }); | ||
}); | ||
|
||
it('was generated correctly', async () => { | ||
assertGeneratedCorrectly({ projectRoot: cwd, testAppLocation }); | ||
}); | ||
|
||
it('runs tests', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'test', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
it('lints all pass', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
}); |
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,75 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
import { assertGeneratedCorrectly } from '../assertions.js'; | ||
import { | ||
createAddon, | ||
createTmp, | ||
dirContents, | ||
install, | ||
runScript, | ||
SUPPORTED_PACKAGE_MANAGERS, | ||
} from '../utils.js'; | ||
|
||
for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { | ||
describe(`--typescript with ${packageManager}`, () => { | ||
let cwd = ''; | ||
let tmpDir = ''; | ||
let distDir = ''; | ||
|
||
beforeAll(async () => { | ||
tmpDir = await createTmp(); | ||
|
||
let { name } = await createAddon({ | ||
args: ['--typescript', `--${packageManager}=true`, '--skip-npm'], | ||
options: { cwd: tmpDir }, | ||
}); | ||
|
||
cwd = path.join(tmpDir, name); | ||
distDir = path.join(cwd, name, 'dist'); | ||
|
||
await install({ cwd, packageManager, skipPrepare: true }); | ||
}); | ||
|
||
afterAll(async () => { | ||
await fs.rm(tmpDir, { recursive: true, force: true }); | ||
}); | ||
|
||
it('was generated correctly', async () => { | ||
await runScript({ cwd, script: 'build', packageManager: 'pnpm' }); | ||
|
||
assertGeneratedCorrectly({ projectRoot: cwd }); | ||
}); | ||
|
||
it('builds the addon', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'build', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
|
||
let contents = await dirContents(distDir); | ||
|
||
expect(contents).to.deep.equal([ | ||
'index.d.ts', | ||
'index.d.ts.map', | ||
'index.js', | ||
'index.js.map', | ||
'template-registry.d.ts', | ||
'template-registry.js', | ||
'template-registry.js.map', | ||
]); | ||
}); | ||
|
||
it('runs tests', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'test', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
it('lints all pass', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
}); | ||
} |
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,107 @@ | ||
import fse from 'fs-extra'; | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
import { assertGeneratedCorrectly } from '../assertions.js'; | ||
import { | ||
createAddon, | ||
createTmp, | ||
dirContents, | ||
install, | ||
runScript, | ||
SUPPORTED_PACKAGE_MANAGERS, | ||
} from '../utils.js'; | ||
|
||
for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { | ||
describe(`defaults with ${packageManager}`, () => { | ||
let cwd = ''; | ||
let tmpDir = ''; | ||
let distDir = ''; | ||
|
||
beforeAll(async () => { | ||
tmpDir = await createTmp(); | ||
|
||
console.debug(`Debug test repo at ${tmpDir}`); | ||
|
||
let { name } = await createAddon({ | ||
args: [`--${packageManager}=true`], | ||
options: { cwd: tmpDir }, | ||
}); | ||
|
||
cwd = path.join(tmpDir, name); | ||
distDir = path.join(cwd, name, 'dist'); | ||
|
||
await install({ cwd, packageManager }); | ||
}); | ||
|
||
afterAll(async () => { | ||
fs.rm(tmpDir, { recursive: true, force: true }); | ||
}); | ||
|
||
it('is using the correct packager', async () => { | ||
let npm = path.join(cwd, 'package-lock.json'); | ||
let yarn = path.join(cwd, 'yarn.lock'); | ||
let pnpm = path.join(cwd, 'pnpm-lock.yaml'); | ||
|
||
switch (packageManager) { | ||
case 'npm': { | ||
expect(await fse.pathExists(npm), 'for NPM: package-lock.json exists').toBe(true); | ||
expect(await fse.pathExists(yarn), 'yarn.lock does not exist').toBe(false); | ||
expect(await fse.pathExists(pnpm), 'pnpm-lock.yaml does not exist').toBe(false); | ||
|
||
break; | ||
} | ||
case 'yarn': { | ||
expect(await fse.pathExists(yarn), 'for Yarn: yarn.lock exists').toBe(true); | ||
expect(await fse.pathExists(npm), 'package-lock.json does not exist').toBe(false); | ||
expect(await fse.pathExists(pnpm), 'pnpm-lock.yaml does not exist').toBe(false); | ||
|
||
break; | ||
} | ||
case 'pnpm': { | ||
expect(await fse.pathExists(pnpm), 'for pnpm: pnpm-lock.yaml exists').toBe(true); | ||
expect(await fse.pathExists(npm), 'package-lock.json does not exist').toBe(false); | ||
expect(await fse.pathExists(yarn), 'yarn.lock does not exist').toBe(false); | ||
|
||
break; | ||
} | ||
|
||
default: | ||
throw new Error(`unknown packageManager: ${packageManager}`); | ||
} | ||
}); | ||
|
||
it('"prepare" built the addon', async () => { | ||
let contents = await dirContents(distDir); | ||
|
||
expect(contents).to.deep.equal(['index.js', 'index.js.map']); | ||
}); | ||
|
||
it('was generated correctly', async () => { | ||
assertGeneratedCorrectly({ projectRoot: cwd }); | ||
}); | ||
|
||
it('builds the addon', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'build', packageManager }); | ||
|
||
expect(exitCode).toEqual(0); | ||
|
||
let contents = await dirContents(distDir); | ||
|
||
expect(contents).to.deep.equal(['index.js', 'index.js.map']); | ||
}); | ||
|
||
it('runs tests', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'test', packageManager }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
it('lints all pass', async () => { | ||
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager }); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.