Skip to content

Commit 93e2c81

Browse files
committed
test: 更新测试用例以反映新功能和修复
- 修改 cli.test.ts 中的期望值,以反映 .prettierignore 文件的创建 - 移除 creator.test.ts 中关于下划线前缀文件处理的测试用例 - 更新 creator.test.ts 中的其他测试用例,以适应新功能和修复
1 parent beaec0f commit 93e2c81

File tree

2 files changed

+1
-45
lines changed

2 files changed

+1
-45
lines changed

test/cli.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ it('创建新脚手架 + biome', async () => {
6565
expect(isFile(toAbs('biome.jsonc'))).toBeTruthy();
6666
expect(isFile(toAbs('eslint.config.mjs'))).toBeFalsy();
6767
expect(isFile(toAbs('prettier.config.mjs'))).toBeFalsy();
68-
expect(isFile(toAbs('.prettierignore'))).toBeFalsy();
68+
expect(isFile(toAbs('.prettierignore'))).toBeTruthy();
6969
expect(readFile('.nvmrc').trim()).toEqual(nodeVersion.toString());
7070
expect(readFile('.npmrc')).toMatch(`registry=${npmRegistry}`);
7171
expect(readFile('README.md')).toMatch(`# ${projectName}`);

test/creator.test.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ beforeAll(async () => {
1919
templateRoot = path.join(templatesRoot, 'default');
2020
// 创建测试模板文件
2121
fse.outputFileSync(path.join(templateRoot, 'file1.txt.ejs'), 'Hello <%= ctx.projectName %>');
22-
fse.outputFileSync(path.join(templateRoot, '__file2.txt.ejs'), 'Hello <%= ctx.projectName %>');
23-
fse.outputFileSync(path.join(templateRoot, '_file3.txt.ejs'), 'Hello <%= ctx.projectName %>');
2422
fse.outputFileSync(path.join(templateRoot, 'path/to/file4.txt'), 'Hello <%= ctx.projectName %>');
2523
});
2624

@@ -195,43 +193,6 @@ it('应该支持自定义扩展数据', async () => {
195193
);
196194
});
197195

198-
it('应该正确处理下划线前缀文件', async () => {
199-
await runTest(async ({ cwd }) => {
200-
const creator = new Creator({
201-
cwd,
202-
templatesRoot,
203-
});
204-
205-
await expectExit(creator.create(), 0);
206-
207-
expect(isFile(path.join(cwd, '__file2.txt.ejs'))).toBe(false);
208-
expect(isFile(path.join(cwd, '__file2.txt'))).toBe(false);
209-
expect(isFile(path.join(cwd, '_file2.txt'))).toBe(true);
210-
expect(isFile(path.join(cwd, '.file2.txt'))).toBe(false);
211-
212-
expect(isFile(path.join(cwd, '_file3.txt.ejs'))).toBe(false);
213-
expect(isFile(path.join(cwd, '_file3.txt'))).toBe(false);
214-
expect(isFile(path.join(cwd, '.file3.txt'))).toBe(true);
215-
});
216-
});
217-
218-
it('应该正确处理点前缀文件', async () => {
219-
const fileName = `${Math.random().toString(36).slice(2)}.xx`;
220-
await runTest(async ({ cwd }) => {
221-
fs.writeFileSync(path.join(templateRoot, `_${fileName}`), 'test content');
222-
223-
const creator = new Creator({
224-
cwd,
225-
templatesRoot,
226-
});
227-
228-
await expectExit(creator.create(), 0);
229-
230-
expect(fs.existsSync(path.join(cwd, `.${fileName}`))).toBe(true);
231-
expect(fs.existsSync(path.join(cwd, `_${fileName}`))).toBe(false);
232-
});
233-
});
234-
235196
it('写入文件前拦截 disableRenderEjs', async () => {
236197
await runTest(async ({ cwd }) => {
237198
const creator = new Creator({
@@ -297,15 +258,10 @@ it('写入文件前拦截 targetFileName', async () => {
297258
expect(isFile(path.join(cwd, 'file1.txt.ejs'))).toBe(true);
298259
expect(isFile(path.join(cwd, 'file1.txt'))).toBe(false);
299260

300-
expect(isFile(path.join(cwd, '__file2.txt.ejs'))).toBe(true);
301-
expect(isFile(path.join(cwd, '_file3.txt.ejs'))).toBe(true);
302-
303261
expect(isFile(path.join(cwd, 'path/to/file4.txt'))).toBe(false);
304262
expect(isFile(path.join(cwd, 'path/to/file4.txt.ok'))).toBe(true);
305263

306264
expect(fs.readFileSync(path.join(cwd, 'file1.txt.ejs'), 'utf8')).not.toMatch('<%=');
307-
expect(fs.readFileSync(path.join(cwd, '__file2.txt.ejs'), 'utf8')).not.toMatch('<%=');
308-
expect(fs.readFileSync(path.join(cwd, '_file3.txt.ejs'), 'utf8')).not.toMatch('<%=');
309265
expect(fs.readFileSync(path.join(cwd, 'path/to/file4.txt.ok'), 'utf8')).toMatch('<%=');
310266
});
311267
});

0 commit comments

Comments
 (0)