Skip to content

Commit

Permalink
chore: downgrade prettier to use inline snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jan 11, 2025
1 parent a766cd3 commit fd9d43d
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 270 deletions.
5 changes: 3 additions & 2 deletions docs/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ pre > code {
color: #333;
}

a, a:visited {
a,
a:visited {
color: #333;
}
a:hover {
color: #999;
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
],
"prettier": {
"semi": false,
"singleQuote": true
"singleQuote": true,
"trailingComma": "all"
},
"engines": {
"node": ">= 18.0.0"
Expand Down Expand Up @@ -106,7 +107,7 @@
"lint-staged": "^15.2.2",
"next": "^15.0.4",
"picocolors": "^1.0.0",
"prettier": "^3.0.0",
"prettier": "2.8.8",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"typescript": "^5.7.2"
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ async function run(args: CliArgs) {
}

if (watch) {
logger.log(`Watching project ${cwd}...`)
logger.log(`Watching changes in the project directory...`)
}

try {
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/alias-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ export function aliasEntries({
let matchedBundlePath: string | undefined
if (dts) {
// Find the type with format condition first
matchedBundlePath = exportMapEntries.find(findTypesFileCallback)
?.bundlePath
matchedBundlePath = exportMapEntries.find(
findTypesFileCallback,
)?.bundlePath
// If theres no format specific types such as import.types or require.types,
// fallback to the general types file.
if (!matchedBundlePath) {
Expand Down
29 changes: 14 additions & 15 deletions test/cli/output-in-watch/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { createCliTest } from '../../testing-utils'
import { createJob } from '../../testing-utils'

describe('cli', () => {
describe('cli - output-in-watch', () => {
const { job } = createJob({
directory: __dirname,
args: ['hello.js', '-w', '-o', 'dist/hello.bundle.js'],
abortTimeout: 3000,
})
it(`cli output-in-watch should work properly`, async () => {
await createCliTest(
{
directory: __dirname,
args: ['hello.js', '-w', '-o', 'dist/hello.bundle.js'],
abortTimeout: 3000,
},
({ signal, stdout, stderr }) => {
console.log('stdout', stdout, stderr)
expect(stdout.includes('Watching project')).toBe(true)
expect(stdout.includes('Exports')).toBe(false)
expect(signal).toBe('SIGTERM') // SIGTERM exit code
},
)
const { signal, stdout } = job

expect(stdout).toMatchInlineSnapshot(`
"Watching changes in the project directory...
"
`)
expect(signal).toBe('SIGTERM') // SIGTERM exit code
})
})
29 changes: 15 additions & 14 deletions test/integration/entry-index-index/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { createIntegrationTest, assertFilesContent } from '../../testing-utils'
import {
assertFilesContent,
createJob,
stripANSIColor,
} from '../../testing-utils'

describe('integration entry-index-index', () => {
const { distDir, job } = createJob({
directory: __dirname,
})
it('should work with index file inside index directory', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
async ({ distDir, stdout }) => {
await assertFilesContent(distDir, {
'default.js': /'index'/,
'react-server.js': /\'react-server\'/,
})
await assertFilesContent(distDir, {
'default.js': /'index'/,
'react-server.js': /\'react-server\'/,
})

expect(stdout).toContain('dist/react-server.js')
expect(stdout).toContain('dist/default.js')
},
)
const stdout = stripANSIColor(job.stdout)
expect(stdout).toContain('. dist/default.js')
expect(stdout).toContain('. (react-server) dist/react-server.js')
})
})

This file was deleted.

65 changes: 44 additions & 21 deletions test/integration/mixed-directives/mixed-directives.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
import { readFileSync } from 'fs'
import {
createIntegrationTest,
getFileNamesFromDirectory,
} from '../../testing-utils'
import { getFileContents, createJob } from '../../testing-utils'

describe('integration - mixed-directives', () => {
const { distDir } = createJob({
directory: __dirname,
})
it('should work with js only project', async () => {
await createIntegrationTest(
const fileContents = await getFileContents(distDir)

expect(fileContents).toMatchInlineSnapshot(`
{
directory: __dirname,
},
async ({ distDir }) => {
const distFiles = await getFileNamesFromDirectory(distDir)
const fileContents = distFiles
.map((file) => [file, readFileSync(`${distDir}/${file}`, 'utf-8')])
.reduce((acc, pair) => {
return {
...acc,
[pair[0]]: pair[1],
}
}, {})
"action-server-DOTFC6td.js": "'use server';
async function action1() {
return 'action1';
}
export { action1 as a };
",
"client.js": "'use client';
import { jsx } from 'react/jsx-runtime';
import { a as action1 } from './action-server-DOTFC6td.js';
function Page() {
return /*#__PURE__*/ jsx("button", {
onClick: action1,
children: "Action 1"
});
}
export { Page as default };
",
"inline.js": "import { jsx } from 'react/jsx-runtime';
import ClientComponent from 'client-component';
// @ts-ignore externals
function Page() {
async function inlineAction() {
'use server';
return 'inline-action';
}
return /*#__PURE__*/ jsx(ClientComponent, {
action: inlineAction
});
}
expect(fileContents).toMatchSnapshot(``)
},
)
export { Page as default };
",
}
`)
})
})
5 changes: 3 additions & 2 deletions test/integration/mixed-directives/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"compilerOptions": {
"jsx": "react-jsx",
"target": "ES2022"
}
}
},
"exclude": ["*.test.ts"]
}
12 changes: 3 additions & 9 deletions test/integration/monorepo-composite-no-incremental/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { join } from 'path'
import { assertContainFiles, createIntegrationTest } from '../../testing-utils'
import { assertContainFiles, createJob } from '../../testing-utils'

describe('integration monorepo-composite-no-incremental', () => {
const { distDir } = createJob({ directory: join(__dirname, 'packages', 'a') })
it('should succeed the build', async () => {
await createIntegrationTest(
{
directory: join(__dirname, 'packages', 'a'),
},
async ({ distDir }) => {
await assertContainFiles(distDir, ['index.js', 'index.d.ts'])
},
)
await assertContainFiles(distDir, ['index.js', 'index.d.ts'])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
{
"path": "./packages/a"
}
]
],
"exclude": ["*.test.ts"]
}
76 changes: 34 additions & 42 deletions test/integration/multi-entries/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
import {
assertFilesContent,
createIntegrationTest,
getChunkFileNamesFromLog,
stripANSIColor,
createJob,
getFileNamesFromDirectory,
} from '../../testing-utils'

describe('integration multi-entries', () => {
describe('integration - multi-entries', () => {
const { dir, distDir, job } = createJob({ directory: __dirname })
it('should contain files', async () => {
await createIntegrationTest(
{
directory: __dirname,
},
async ({ dir, stdout }) => {
const contentsRegex = {
'./dist/index.js': /'index'/,
'./dist/shared/index.mjs': /'shared'/,
'./dist/shared/edge-light.mjs': /'shared.edge-light'/,
'./dist/server/edge.mjs': /'server.edge-light'/,
'./dist/server/react-server.mjs': /'server.react-server'/,
// types
'./dist/server/index.d.ts': `export { Client } from '../client/index.js';\nexport { Shared } from '../shared/index.js';`,
'./dist/client/index.d.ts': `export { Shared } from '../shared/index.js'`,
}
const contentsRegex = {
'./dist/index.js': /'index'/,
'./dist/shared/index.mjs': /'shared'/,
'./dist/shared/edge-light.mjs': /'shared.edge-light'/,
'./dist/server/edge.mjs': /'server.edge-light'/,
'./dist/server/react-server.mjs': /'server.react-server'/,
// types
'./dist/server/index.d.ts': `export { Client } from '../client/index.js';\nexport { Shared } from '../shared/index.js';`,
'./dist/client/index.d.ts': `export { Shared } from '../shared/index.js'`,
}

await assertFilesContent(dir, contentsRegex)
await assertFilesContent(dir, contentsRegex)

const log = `\
dist/index.js
dist/index.d.ts
dist/lite.js
dist/client/index.mjs
dist/client/index.cjs
dist/client/index.d.ts
dist/server/index.mjs
dist/server/index.d.ts
dist/server/edge.mjs
dist/server/react-server.mjs
dist/shared/index.mjs
dist/shared/index.cjs
dist/shared/index.d.ts
dist/shared/edge-light.mjs
`
const files = await getFileNamesFromDirectory(distDir)

const rawStdout = stripANSIColor(stdout)
getChunkFileNamesFromLog(log).forEach((chunk: string) => {
expect(rawStdout).toContain(chunk)
})
},
)
expect(files).toMatchInlineSnapshot(`
[
"client/index.cjs",
"client/index.d.ts",
"client/index.mjs",
"index.d.ts",
"index.js",
"lite.js",
"server/edge.mjs",
"server/index.d.ts",
"server/index.mjs",
"server/react-server.mjs",
"shared/edge-light.mjs",
"shared/index.cjs",
"shared/index.d.ts",
"shared/index.mjs",
]
`)
})
})
Loading

0 comments on commit fd9d43d

Please sign in to comment.