diff options
Diffstat (limited to 'packages/create-astro/test')
4 files changed, 23 insertions, 15 deletions
diff --git a/packages/create-astro/test/fixtures/not-empty/package.json b/packages/create-astro/test/fixtures/not-empty/package.json index 4c5b89162..dad4a5e5c 100644 --- a/packages/create-astro/test/fixtures/not-empty/package.json +++ b/packages/create-astro/test/fixtures/not-empty/package.json @@ -2,6 +2,8 @@ "name": "@test/create-astro-not-empty", "private": true, "scripts": { - "build": "astro build" + "dev": "astro dev", + "build": "astro check && astro build", + "preview": "astro preview" } }
\ No newline at end of file diff --git a/packages/create-astro/test/fixtures/not-empty/tsconfig.json b/packages/create-astro/test/fixtures/not-empty/tsconfig.json index 9e26dfeeb..3fd7ae6e8 100644 --- a/packages/create-astro/test/fixtures/not-empty/tsconfig.json +++ b/packages/create-astro/test/fixtures/not-empty/tsconfig.json @@ -1 +1,3 @@ -{}
\ No newline at end of file +{ + "extends": "astro/tsconfigs/strictest" +}
\ No newline at end of file diff --git a/packages/create-astro/test/typescript.test.js b/packages/create-astro/test/typescript.test.js index a6c09af99..30697bbe4 100644 --- a/packages/create-astro/test/typescript.test.js +++ b/packages/create-astro/test/typescript.test.js @@ -84,6 +84,8 @@ describe('typescript', () => { }); describe('typescript: setup tsconfig', () => { + beforeEach(() => resetFixtures()); + it('none', async () => { const root = new URL('./fixtures/empty/', import.meta.url); const tsconfig = new URL('./tsconfig.json', root); @@ -92,8 +94,6 @@ describe('typescript: setup tsconfig', () => { expect(JSON.parse(fs.readFileSync(tsconfig, { encoding: 'utf-8' }))).to.deep.eq({ extends: 'astro/tsconfigs/strict', }); - - await resetFixtures(); }); it('exists', async () => { @@ -103,20 +103,18 @@ describe('typescript: setup tsconfig', () => { expect(JSON.parse(fs.readFileSync(tsconfig, { encoding: 'utf-8' }))).to.deep.eq({ extends: 'astro/tsconfigs/strict', }); - - await resetFixtures(); }); }); describe('typescript: setup package', () => { + beforeEach(() => resetFixtures()); + it('none', async () => { const root = new URL('./fixtures/empty/', import.meta.url); const packageJson = new URL('./package.json', root); await setupTypeScript('strictest', { cwd: fileURLToPath(root), install: false }); expect(fs.existsSync(packageJson)).to.be.false; - - await resetFixtures(); }); it('none', async () => { @@ -127,10 +125,12 @@ describe('typescript: setup package', () => { 'astro build' ); await setupTypeScript('strictest', { cwd: fileURLToPath(root), install: false }); - expect(JSON.parse(fs.readFileSync(packageJson, { encoding: 'utf-8' })).scripts.build).to.be.eq( - 'astro check && astro build' + const { scripts } = JSON.parse(fs.readFileSync(packageJson, { encoding: 'utf-8' })); + + expect(Object.keys(scripts)).to.deep.eq(['dev', 'build', 'preview'], 'does not override existing scripts'); + expect(scripts.build).to.eq( + 'astro check && astro build', + 'prepends astro check command' ); - - await resetFixtures(); }); }); diff --git a/packages/create-astro/test/utils.js b/packages/create-astro/test/utils.js index 56ef55605..f83769e0f 100644 --- a/packages/create-astro/test/utils.js +++ b/packages/create-astro/test/utils.js @@ -33,18 +33,22 @@ export function setup() { const resetEmptyFixture = () => fs.promises.rm(new URL('./fixtures/empty/tsconfig.json', import.meta.url)); + const resetNotEmptyFixture = async () => { const packagePath = new URL('./fixtures/not-empty/package.json', import.meta.url); const tsconfigPath = new URL('./fixtures/not-empty/tsconfig.json', import.meta.url); + const packageJsonData = JSON.parse(await fs.promises.readFile(packagePath, { encoding: 'utf-8' })); const overriddenPackageJson = Object.assign( - JSON.parse(await fs.promises.readFile(packagePath, { encoding: 'utf-8' })), + packageJsonData, { scripts: { + dev: 'astro dev', build: 'astro build', - }, + preview: 'astro preview' + } } - ); + ) return Promise.all([ fs.promises.writeFile(packagePath, JSON.stringify(overriddenPackageJson, null, 2), { |