1 | import tap from 'tap'
|
2 | import path from 'path'
|
3 |
|
4 | import { isStatic, isDynamic, getFiles } from '../lib/getFiles'
|
5 | import type { Presta } from '../lib/types'
|
6 |
|
7 | tap.test('getFiles - isStatic', async (t) => {
|
8 | const fixtures = {
|
9 | no: 'noGetStaticPaths.js',
|
10 | yes: 'getStaticPaths.js',
|
11 | arrow: 'getStaticPathsArrow.js',
|
12 | }
|
13 |
|
14 | t.testdir({
|
15 | [fixtures.no]: `export function handler () {}`,
|
16 | [fixtures.yes]: `export function getStaticPaths () {}`,
|
17 | [fixtures.arrow]: `export const getStaticPaths = () => {}`,
|
18 | })
|
19 |
|
20 | t.equal(isStatic(path.join(t.testdirName, fixtures.no)), false)
|
21 | t.equal(isStatic(path.join(t.testdirName, fixtures.yes)), true)
|
22 | t.equal(isStatic(path.join(t.testdirName, fixtures.arrow)), true)
|
23 | })
|
24 |
|
25 | tap.test('getFiles - isDynamic', async (t) => {
|
26 | const fixtures = {
|
27 | no: 'noRoute.js',
|
28 | yes: 'route.js',
|
29 | }
|
30 |
|
31 | t.testdir({
|
32 | [fixtures.no]: `export function handler() {}`,
|
33 | [fixtures.yes]: `export const route = '/';`,
|
34 | })
|
35 |
|
36 | t.equal(isDynamic(path.join(t.testdirName, fixtures.no)), false)
|
37 | t.equal(isDynamic(path.join(t.testdirName, fixtures.yes)), true)
|
38 | })
|
39 |
|
40 | tap.test('getFiles - getFiles', async (t) => {
|
41 | t.testdir({
|
42 | 'noMatch.getFiles.js': 'export function handler() {}',
|
43 | 'hybrid.getFiles.js': `export const route = '*';export function getStaticPaths() {};`,
|
44 | 'static.getFiles.js': `export function getStaticPaths() {};`,
|
45 | })
|
46 |
|
47 | const results = getFiles({
|
48 | cwd: process.cwd(),
|
49 | files: [path.join(t.testdirName, '*.getFiles.js')],
|
50 | } as Presta)
|
51 |
|
52 | t.equal(results.length, 3)
|
53 | })
|