-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-abell): add bun template, and option to skip dep installa…
…tion (#172)
- Loading branch information
1 parent
c84bbf3
commit 04661a5
Showing
17 changed files
with
436 additions
and
51 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
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,129 @@ | ||
/* eslint-disable max-len */ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { spawn } from 'child_process'; | ||
import { | ||
afterAll, | ||
afterEach, | ||
beforeAll, | ||
beforeEach, | ||
describe, | ||
expect, | ||
test, | ||
vi | ||
} from 'vitest'; | ||
import create from '../create'; | ||
import { deleteDir, windowsifyCommand } from '../utils.js'; | ||
|
||
const testUtilsDir = path.join(__dirname, 'test-utils', 'scaffolds'); | ||
|
||
vi.mock('child_process'); | ||
|
||
// Shoutout to chatgpt for this function | ||
const makeTree = (directoryPath: string, indent = 0) => { | ||
const files = fs | ||
.readdirSync(directoryPath) | ||
// sorting to make directory read sequence same | ||
.sort(); | ||
|
||
let tree = ''; | ||
|
||
files.forEach((file) => { | ||
const filePath = path.join(directoryPath, file); | ||
const stats = fs.statSync(filePath); | ||
const isDirectory = stats.isDirectory(); | ||
|
||
tree += ' '.repeat(indent * 2); | ||
tree += isDirectory ? '├── ' + file + '\n' : '└── ' + file + '\n'; | ||
|
||
if (isDirectory) { | ||
tree += makeTree(filePath, indent + 1); | ||
} | ||
}); | ||
|
||
return tree; | ||
}; | ||
|
||
beforeAll(() => { | ||
deleteDir(testUtilsDir); | ||
}); | ||
|
||
afterAll(() => { | ||
deleteDir(testUtilsDir); | ||
}); | ||
|
||
describe('create', () => { | ||
beforeEach(() => { | ||
vi.spyOn(process, 'cwd').mockReturnValue(testUtilsDir); | ||
// @ts-expect-error: only mocking what is used | ||
spawn.mockImplementation(() => { | ||
const mockChildProcess = { | ||
stdout: { on: vi.fn() }, // Mock stdout behavior if needed | ||
stderr: { on: vi.fn() }, // Mock stderr behavior if needed | ||
on: vi.fn() | ||
}; | ||
return mockChildProcess; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
deleteDir(path.join(testUtilsDir, 'hello-abell')); | ||
}); | ||
|
||
test('should create project with default template', async () => { | ||
await create('hello-abell', { | ||
installer: 'skip', | ||
template: 'default' | ||
}); | ||
|
||
expect(spawn).not.toBeCalled(); | ||
expect(fs.existsSync(path.join(testUtilsDir, 'hello-abell'))).toBe(true); | ||
expect(makeTree(path.join(testUtilsDir, 'hello-abell'))) | ||
.toMatchInlineSnapshot(` | ||
"├── _components | ||
└── global.meta.abell | ||
└── navbar.abell | ||
└── about.abell | ||
├── client-assets | ||
└── global.css | ||
└── index-client.js | ||
└── config.js | ||
└── index.abell | ||
└── package.json | ||
├── public | ||
└── abell-logo.svg | ||
" | ||
`); | ||
}); | ||
|
||
test('should create project with default template and bun installer', async () => { | ||
await create('hello-abell', { | ||
installer: 'bun', | ||
template: 'default' | ||
}); | ||
|
||
const expectedCommand = 'bun install'; | ||
const commandArgs = windowsifyCommand(expectedCommand).split(' '); | ||
|
||
expect(spawn).toBeCalledWith(commandArgs[0], [commandArgs[1]], { | ||
cwd: path.join(testUtilsDir, 'hello-abell'), | ||
stdio: 'inherit' | ||
}); | ||
|
||
const packageJSONPath = path.join( | ||
testUtilsDir, | ||
'hello-abell', | ||
'package.json' | ||
); | ||
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8')); | ||
|
||
expect(packageJSON.name).toBe('hello-abell'); | ||
expect(packageJSON.scripts).toMatchInlineSnapshot(` | ||
{ | ||
"dev": "bunx --bun abell dev", | ||
"generate": "bunx --bun abell generate", | ||
} | ||
`); | ||
}); | ||
}); |
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
6 changes: 5 additions & 1 deletion
6
packages/create-abell/src/__tests__/test-utils/test-package.json
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"name": "unset", | ||
"version": "0.0.15", | ||
"description": "test-description" | ||
"description": "test-description", | ||
"scripts": { | ||
"dev": "abell dev", | ||
"generate": "abell generate" | ||
} | ||
} |
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
Oops, something went wrong.