-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcli.test.ts
More file actions
104 lines (90 loc) · 2.53 KB
/
Copy pathcli.test.ts
File metadata and controls
104 lines (90 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { beforeEach, expect, test } from '@rstest/core';
import { create } from '../src';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixturesDir = path.join(__dirname, 'fixtures', 'cli');
const testDir = path.join(fixturesDir, 'test-temp-output');
beforeEach(() => {
// Clean up test directory before each test
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true });
}
fs.mkdirSync(testDir, { recursive: true });
// Return cleanup function
return () => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true });
}
};
});
test('should accept comma separated tools option', async () => {
const projectDir = path.join(testDir, 'comma-separated-tools');
await create({
name: 'test',
root: fixturesDir,
templates: ['vanilla'],
getTemplateName: async () => 'vanilla',
argv: [
'node',
'test',
'--dir',
projectDir,
'--template',
'vanilla',
'--tools',
'eslint,prettier',
],
});
expect(fs.existsSync(path.join(projectDir, 'eslint.config.mjs'))).toBe(true);
expect(fs.existsSync(path.join(projectDir, '.prettierrc'))).toBe(true);
});
test('should scaffold rslint tool files', async () => {
const projectDir = path.join(testDir, 'rslint-tool');
await create({
name: 'test',
root: fixturesDir,
templates: ['vanilla'],
getTemplateName: async () => 'vanilla',
argv: [
'node',
'test',
'--dir',
projectDir,
'--template',
'vanilla',
'--tools',
'rslint',
],
});
expect(fs.existsSync(path.join(projectDir, 'rslint.config.ts'))).toBe(true);
const packageJson = JSON.parse(
fs.readFileSync(path.join(projectDir, 'package.json'), 'utf-8'),
);
expect(packageJson.scripts).toMatchObject({
lint: 'rslint',
});
expect(packageJson.devDependencies['@rslint/core']).toBeTruthy();
});
test('should skip tools selection', async () => {
const projectDir = path.join(testDir, 'comma-separated-tools');
await create({
name: 'test',
root: fixturesDir,
templates: ['vanilla'],
getTemplateName: async () => 'vanilla',
argv: [
'node',
'test',
'--dir',
projectDir,
'--template',
'vanilla',
'--tools',
'""',
],
});
expect(fs.existsSync(path.join(projectDir, 'eslint.config.mjs'))).toBe(false);
expect(fs.existsSync(path.join(projectDir, '.prettierrc'))).toBe(false);
});