-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
124 additions
and
18 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ test/**/*.js.map | |
test/**/tsconfig.json | ||
!test/**/node_modules | ||
.next | ||
.vscode |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,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(/<name>/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 <test-name>') | ||
process.exit(1) | ||
} | ||
|
||
createProjectFromFixtures(testName) |
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
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,14 @@ | ||
import { createIntegrationTest, assertContainFiles } from 'testing-utils' | ||
|
||
describe('integration - <name>', () => { | ||
it('should work', async () => { | ||
await createIntegrationTest( | ||
{ | ||
directory: __dirname, | ||
}, | ||
({ distDir }) => { | ||
assertContainFiles(distDir, ['index.js']) | ||
}, | ||
) | ||
}) | ||
}) |
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,8 @@ | ||
{ | ||
"name": "<name>", | ||
"main": "./dist/index.js", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/index.js" | ||
} | ||
} |
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,3 @@ | ||
export function Foo() { | ||
return <p>Foo</p> | ||
} |
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
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