diff --git a/.gitignore b/.gitignore index 1bd3744b..1917a578 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ test/**/*.js.map test/**/tsconfig.json !test/**/node_modules .next +.vscode diff --git a/package.json b/package.json index e097c4e9..48a228ef 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "docs:dev": "next dev docs", "docs:build": "next build docs", "clean": "rm -rf ./dist", + "new-test": "node ./scripts/new-test.js", "typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit", "prepare-release": "pnpm clean && pnpm build", "publish-local": "pnpm prepare-release && pnpm test && pnpm publish", @@ -108,7 +109,7 @@ "prettier": "^3.0.0", "react": "^19.0.0", "react-dom": "^19.0.0", - "typescript": "^5.6.2" + "typescript": "^5.7.2" }, "lint-staged": { "*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write" @@ -127,7 +128,8 @@ }, "testPathIgnorePatterns": [ "/node_modules/", - "/test/integration/.*/*src" + "/test/integration/.*/*src", + "/test/fixtures" ], "testTimeout": 60000 }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a3d17469..4facffc0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -55,7 +55,7 @@ importers: version: 4.27.4 rollup-plugin-dts: specifier: ^6.1.1 - version: 6.1.1(rollup@4.27.4)(typescript@5.6.2) + version: 6.1.1(rollup@4.27.4)(typescript@5.7.3) rollup-plugin-swc3: specifier: ^0.11.1 version: 0.11.1(@swc/core@1.9.3(@swc/helpers@0.5.11))(rollup@4.27.4) @@ -74,7 +74,7 @@ importers: version: 1.0.0 '@swc-node/register': specifier: ^1.10.9 - version: 1.10.9(@swc/core@1.9.3(@swc/helpers@0.5.11))(@swc/types@0.1.9)(typescript@5.6.2) + version: 1.10.9(@swc/core@1.9.3(@swc/helpers@0.5.11))(@swc/types@0.1.9)(typescript@5.7.3) '@swc/jest': specifier: ^0.2.31 version: 0.2.31(@swc/core@1.9.3(@swc/helpers@0.5.11)) @@ -130,8 +130,8 @@ importers: specifier: ^19.0.0 version: 19.0.0(react@19.0.0) typescript: - specifier: ^5.6.2 - version: 5.6.2 + specifier: ^5.7.2 + version: 5.7.3 packages: @@ -2196,8 +2196,8 @@ packages: resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} engines: {node: '>=10'} - typescript@5.6.2: - resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} + typescript@5.7.3: + resolution: {integrity: sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==} engines: {node: '>=14.17'} hasBin: true @@ -3039,7 +3039,7 @@ snapshots: '@swc/core': 1.9.3(@swc/helpers@0.5.11) '@swc/types': 0.1.9 - '@swc-node/register@1.10.9(@swc/core@1.9.3(@swc/helpers@0.5.11))(@swc/types@0.1.9)(typescript@5.6.2)': + '@swc-node/register@1.10.9(@swc/core@1.9.3(@swc/helpers@0.5.11))(@swc/types@0.1.9)(typescript@5.7.3)': dependencies: '@swc-node/core': 1.13.3(@swc/core@1.9.3(@swc/helpers@0.5.11))(@swc/types@0.1.9) '@swc-node/sourcemap-support': 0.5.1 @@ -3049,7 +3049,7 @@ snapshots: oxc-resolver: 1.12.0 pirates: 4.0.6 tslib: 2.7.0 - typescript: 5.6.2 + typescript: 5.7.3 transitivePeerDependencies: - '@swc/types' - supports-color @@ -4283,11 +4283,11 @@ snapshots: rfdc@1.3.0: {} - rollup-plugin-dts@6.1.1(rollup@4.27.4)(typescript@5.6.2): + rollup-plugin-dts@6.1.1(rollup@4.27.4)(typescript@5.7.3): dependencies: magic-string: 0.30.14 rollup: 4.27.4 - typescript: 5.6.2 + typescript: 5.7.3 optionalDependencies: '@babel/code-frame': 7.24.7 @@ -4511,7 +4511,7 @@ snapshots: type-fest@0.21.3: {} - typescript@5.6.2: {} + typescript@5.7.3: {} undici-types@6.19.8: {} diff --git a/scripts/new-test.js b/scripts/new-test.js new file mode 100644 index 00000000..63c909d3 --- /dev/null +++ b/scripts/new-test.js @@ -0,0 +1,68 @@ +// @ts-check + +const fs = require('fs') +const path = require('path') + +// Helper to copy and rename a file +const copyAndRenameFile = (srcPath, destPath, testName) => { + const content = fs.readFileSync(srcPath, 'utf8') + const updatedContent = content.replace(//g, testName) // Replace placeholder + fs.writeFileSync(destPath, updatedContent, 'utf8') + console.log(`Created file: ${destPath}`) +} + +// Helper to copy folder contents recursively +const copyFolder = (srcFolder, destFolder, testName) => { + if (!fs.existsSync(destFolder)) { + fs.mkdirSync(destFolder, { recursive: true }) + } + + const items = fs.readdirSync(srcFolder, { withFileTypes: true }) + for (const item of items) { + const srcPath = path.join(srcFolder, item.name) + const destPath = path.join( + destFolder, + item.name.replace(/test\.js/, `${testName}.test.js`), + ) + + if (item.isDirectory()) { + copyFolder(srcPath, destPath, testName) + } else { + copyAndRenameFile(srcPath, destPath, testName) + } + } +} + +const createProjectFromFixtures = (testName) => { + const fixturesDir = path.resolve( + __dirname, + '..', + 'test', + 'fixtures', + 'integration-test-template', + ) + const testIntegrationFolder = path.resolve( + __dirname, + '..', + 'test', + 'integration', + ) + const outputDir = path.join(testIntegrationFolder, testName) + + if (!fs.existsSync(fixturesDir)) { + console.error('Fixtures folder not found!') + process.exit(1) + } + + copyFolder(fixturesDir, outputDir, testName) + console.log(`Project structure created for: ${testName}`) +} + +// Run the script +const testName = process.argv[2] +if (!testName) { + console.error('Please provide a test name. pnpm new-test ') + process.exit(1) +} + +createProjectFromFixtures(testName) diff --git a/test/unit/memoize.test.ts b/src/lib/memoize.test.ts similarity index 93% rename from test/unit/memoize.test.ts rename to src/lib/memoize.test.ts index dbd12bc4..124a35c8 100644 --- a/test/unit/memoize.test.ts +++ b/src/lib/memoize.test.ts @@ -1,4 +1,4 @@ -import { memoizeByKey } from '../../src/lib/memoize' +import { memoizeByKey } from './memoize' describe('memoize', () => { it('should memoize the function by default based on arg', () => { diff --git a/test/fixtures/integration-test-template/index.test.ts b/test/fixtures/integration-test-template/index.test.ts new file mode 100644 index 00000000..0e1beedb --- /dev/null +++ b/test/fixtures/integration-test-template/index.test.ts @@ -0,0 +1,14 @@ +import { createIntegrationTest, assertContainFiles } from 'testing-utils' + +describe('integration - ', () => { + it('should work', async () => { + await createIntegrationTest( + { + directory: __dirname, + }, + ({ distDir }) => { + assertContainFiles(distDir, ['index.js']) + }, + ) + }) +}) diff --git a/test/fixtures/integration-test-template/package.json b/test/fixtures/integration-test-template/package.json new file mode 100644 index 00000000..3506284f --- /dev/null +++ b/test/fixtures/integration-test-template/package.json @@ -0,0 +1,8 @@ +{ + "name": "", + "main": "./dist/index.js", + "type": "module", + "exports": { + ".": "./dist/index.js" + } +} diff --git a/test/fixtures/integration-test-template/src/index.js b/test/fixtures/integration-test-template/src/index.js new file mode 100644 index 00000000..d32a1bca --- /dev/null +++ b/test/fixtures/integration-test-template/src/index.js @@ -0,0 +1,3 @@ +export function Foo() { + return

Foo

+} diff --git a/test/tsconfig.json b/test/tsconfig.json index efa4e9af..66924cd1 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -3,10 +3,18 @@ "compilerOptions": { "module": "ESNext", "target": "ESNext", + "strict": false, "baseUrl": "..", "paths": { - "bunchee": ["./src/index.ts"] + "bunchee": ["./src/index.ts"], + "testing-utils": ["./test/integration/utils.ts"] } }, - "include": ["./**/*.test.ts", "../src/**/*.test.ts"] + "include": [ + "**/*.test.ts", + "**/*.test.tsx", + "../src/**/*.test.ts", + "../src/**/*.test.tsx" + ], + "references": [{ "path": "../tsconfig.json" }] } diff --git a/tsconfig.json b/tsconfig.json index 045af91d..faf212ad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { - "include": ["./src", "./*.ts", "./*.d.ts", "test/unit/memoize.test.ts"], "compilerOptions": { + "composite": true, "rootDir": ".", "outDir": "./dist", "target": "ES2019", @@ -15,5 +15,7 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true - } + }, + "references": [{ "path": "./test/tsconfig.json" }], + "include": ["src", "*.d.ts"] }