Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { finalizeAddOns, getAllAddOns } from '../src/add-ons.js'
4
5import type { AddOn, Framework } from '../src/types.js'
6
7describe('getAllAddOns', () => {
8 it('filter add-ons', () => {
9 const addOns = getAllAddOns(
10 {
11 id: 'react-cra',
12 getAddOns: () => [
13 {
14 id: 'add-on-1',
15 description: 'Add-on 1',
16 modes: ['file-router'],
17 } as AddOn,
18 {
19 id: 'add-on-2',
20 description: 'Add-on 2',
21 modes: ['code-router'],
22 } as AddOn,
23 ],
24 } as Framework,
25 'file-router',
26 )
27
28 expect(addOns.length).toEqual(1)
29 expect(addOns[0].id).toEqual('add-on-1')
30 })
31})
32
33describe('finalizeAddOns', () => {
34 it('should finalize add-ons', async () => {
35 const addOns = await finalizeAddOns(
36 {
37 id: 'react-cra',
38 getAddOns: () => [
39 {
40 id: 'add-on-1',
41 description: 'Add-on 1',
42 modes: ['file-router'],
43 dependsOn: ['add-on-2'],
44 } as AddOn,
45 {
46 id: 'add-on-2',
47 description: 'Add-on 2',
48 modes: ['file-router'],
49 } as AddOn,
50 {
51 id: 'add-on-3',
52 description: 'Add-on 3',
53 modes: ['file-router'],
54 } as AddOn,
55 ],
56 } as Framework,
57 'file-router',
58 ['add-on-1'],
59 )
60
61 expect(addOns.length).toEqual(2)
62 const addOnIds = addOns.map((a) => a.id)
63 expect(addOnIds.includes('add-on-1')).toEqual(true)
64 expect(addOnIds.includes('add-on-2')).toEqual(true)
65 expect(addOnIds.includes('add-on-3')).toEqual(false)
66 })
67})