diff options
author | 2023-10-24 05:14:33 +0700 | |
---|---|---|
committer | 2023-10-23 17:14:33 -0500 | |
commit | ce807a2bfef325683bfdb01065a73c4e2b0a5fe5 (patch) | |
tree | 31c8a8bdaad2af2e239d364342e40b9097a36498 /packages/create-astro/test | |
parent | e3c18be5d09cd46e6ba1c00171db7eab6ae93d6f (diff) | |
download | astro-ce807a2bfef325683bfdb01065a73c4e2b0a5fe5.tar.gz astro-ce807a2bfef325683bfdb01065a73c4e2b0a5fe5.tar.zst astro-ce807a2bfef325683bfdb01065a73c4e2b0a5fe5.zip |
feat(create-astro): automatically configure `astro check` (#8853)
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r-- | packages/create-astro/test/fixtures/not-empty/package.json | 7 | ||||
-rw-r--r-- | packages/create-astro/test/project-name.test.js | 2 | ||||
-rw-r--r-- | packages/create-astro/test/typescript.test.js | 38 | ||||
-rw-r--r-- | packages/create-astro/test/utils.js | 27 |
4 files changed, 67 insertions, 7 deletions
diff --git a/packages/create-astro/test/fixtures/not-empty/package.json b/packages/create-astro/test/fixtures/not-empty/package.json index 5edb64fea..4c5b89162 100644 --- a/packages/create-astro/test/fixtures/not-empty/package.json +++ b/packages/create-astro/test/fixtures/not-empty/package.json @@ -1,4 +1,7 @@ { "name": "@test/create-astro-not-empty", - "private": true -} + "private": true, + "scripts": { + "build": "astro build" + } +}
\ No newline at end of file diff --git a/packages/create-astro/test/project-name.test.js b/packages/create-astro/test/project-name.test.js index 1672fce66..905f4a158 100644 --- a/packages/create-astro/test/project-name.test.js +++ b/packages/create-astro/test/project-name.test.js @@ -3,7 +3,7 @@ import { expect } from 'chai'; import { projectName } from '../dist/index.js'; import { setup } from './utils.js'; -describe('project name', () => { +describe('project name', async () => { const fixture = setup(); it('pass in name', async () => { diff --git a/packages/create-astro/test/typescript.test.js b/packages/create-astro/test/typescript.test.js index be89a499d..8145e2251 100644 --- a/packages/create-astro/test/typescript.test.js +++ b/packages/create-astro/test/typescript.test.js @@ -4,7 +4,8 @@ import fs from 'node:fs'; import { fileURLToPath } from 'node:url'; import { typescript, setupTypeScript } from '../dist/index.js'; -import { setup } from './utils.js'; +import { setup, resetFixtures } from './utils.js'; +import { describe } from 'node:test'; describe('typescript', () => { const fixture = setup(); @@ -82,7 +83,7 @@ describe('typescript', () => { }); }); -describe('typescript: setup', () => { +describe('typescript: setup tsconfig', () => { it('none', async () => { const root = new URL('./fixtures/empty/', import.meta.url); const tsconfig = new URL('./tsconfig.json', root); @@ -91,7 +92,8 @@ describe('typescript: setup', () => { expect(JSON.parse(fs.readFileSync(tsconfig, { encoding: 'utf-8' }))).to.deep.eq({ extends: 'astro/tsconfigs/strict', }); - fs.rmSync(tsconfig); + + await resetFixtures(); }); it('exists', async () => { @@ -101,6 +103,34 @@ describe('typescript: setup', () => { expect(JSON.parse(fs.readFileSync(tsconfig, { encoding: 'utf-8' }))).to.deep.eq({ extends: 'astro/tsconfigs/strict', }); - fs.writeFileSync(tsconfig, `{}`); + + await resetFixtures(); + }); +}); + +describe('typescript: setup package', () => { + 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 () => { + const root = new URL('./fixtures/not-empty/', import.meta.url); + const packageJson = new URL('./package.json', root); + + expect( + JSON.parse(fs.readFileSync(packageJson, { encoding: 'utf-8' })).scripts.build + ).to.be.eq('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' + ); + + await resetFixtures(); }); }); diff --git a/packages/create-astro/test/utils.js b/packages/create-astro/test/utils.js index ff5d5dd83..56ef55605 100644 --- a/packages/create-astro/test/utils.js +++ b/packages/create-astro/test/utils.js @@ -1,3 +1,4 @@ +import fs from 'node:fs'; import { setStdout } from '../dist/index.js'; import stripAnsi from 'strip-ansi'; @@ -29,3 +30,29 @@ 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 overriddenPackageJson = Object.assign( + JSON.parse(await fs.promises.readFile(packagePath, { encoding: 'utf-8' })), + { + scripts: { + build: 'astro build', + }, + } + ); + + return Promise.all([ + fs.promises.writeFile(packagePath, JSON.stringify(overriddenPackageJson, null, 2), { + encoding: 'utf-8', + }), + fs.promises.writeFile(tsconfigPath, '{}', { encoding: 'utf-8' }), + ]); +}; + +export const resetFixtures = () => + Promise.allSettled([resetEmptyFixture(), resetNotEmptyFixture()]); |