-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathtemplates.test.ts
More file actions
65 lines (55 loc) · 2.42 KB
/
Copy pathtemplates.test.ts
File metadata and controls
65 lines (55 loc) · 2.42 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
import { describe, it, expect } from '@jest/globals';
import { promises as fs } from 'node:fs';
import path from 'node:path';
const PACKAGE_ROOT = path.resolve(__dirname, '..');
const TEMPLATES_DIR = path.join(PACKAGE_ROOT, 'templates');
const EXTENSIONS_DIR = path.join(PACKAGE_ROOT, 'extensions');
const EXPECTED_TEMPLATES = ['next-template'];
const EXPECTED_EXTENSIONS = ['precompiles'];
describe('Templates', () => {
it('templates directory exists', async () => {
const stat = await fs.stat(TEMPLATES_DIR);
expect(stat.isDirectory()).toBe(true);
});
it.each(EXPECTED_TEMPLATES)('%s template directory exists', async (template) => {
const templatePath = path.join(TEMPLATES_DIR, template);
const stat = await fs.stat(templatePath);
expect(stat.isDirectory()).toBe(true);
});
it.each(EXPECTED_TEMPLATES)('%s template has a valid package.json', async (template) => {
const pkgPath = path.join(TEMPLATES_DIR, template, 'package.json');
const contents = await fs.readFile(pkgPath, 'utf-8');
const parsed = JSON.parse(contents);
expect(typeof parsed.name).toBe('string');
expect(parsed.name.trim().length).toBeGreaterThan(0);
expect(typeof parsed.version).toBe('string');
});
it.each(EXPECTED_TEMPLATES)('%s template has a tsconfig.json', async (template) => {
const tsconfigPath = path.join(TEMPLATES_DIR, template, 'tsconfig.json');
const stat = await fs.stat(tsconfigPath);
expect(stat.isFile()).toBe(true);
});
it.each(EXPECTED_TEMPLATES)('%s template has a src/ directory', async (template) => {
const srcPath = path.join(TEMPLATES_DIR, template, 'src');
const stat = await fs.stat(srcPath);
expect(stat.isDirectory()).toBe(true);
});
});
describe('Extensions', () => {
it('extensions directory exists', async () => {
const stat = await fs.stat(EXTENSIONS_DIR);
expect(stat.isDirectory()).toBe(true);
});
it.each(EXPECTED_EXTENSIONS)('%s extension directory exists', async (extension) => {
const extensionPath = path.join(EXTENSIONS_DIR, extension);
const stat = await fs.stat(extensionPath);
expect(stat.isDirectory()).toBe(true);
});
it.each(EXPECTED_EXTENSIONS)('%s extension has a valid package.json', async (extension) => {
const pkgPath = path.join(EXTENSIONS_DIR, extension, 'package.json');
const contents = await fs.readFile(pkgPath, 'utf-8');
const parsed = JSON.parse(contents);
expect(typeof parsed.name).toBe('string');
expect(parsed.name.trim().length).toBeGreaterThan(0);
});
});