-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: watch all extensions not just root
- Loading branch information
Showing
8 changed files
with
184 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { DEFAULT_OPTIONS } from '../options' | ||
import { DEFAULT_OPTIONS, resolveOptions } from '../options' | ||
import { PrefixTree } from './tree' | ||
import { TreeNodeType } from './treeNodeValue' | ||
|
||
describe('Tree', () => { | ||
const RESOLVED_OPTIONS = resolveOptions(DEFAULT_OPTIONS) | ||
it('creates an empty tree', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
expect(tree.children.size).toBe(0) | ||
}) | ||
|
||
it('creates a tree with a single static path', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('foo.vue') | ||
expect(tree.children.size).toBe(1) | ||
const child = tree.children.get('foo')! | ||
|
@@ -24,7 +25,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('creates a tree with a single param', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[id].vue') | ||
expect(tree.children.size).toBe(1) | ||
const child = tree.children.get('[id]')! | ||
|
@@ -39,7 +40,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('separate param names from static segments', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[id]_a') | ||
tree.insert('[a]e[b]f') | ||
expect(tree.children.get('[id]_a')!.value).toMatchObject({ | ||
|
@@ -58,7 +59,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('creates params in nested files', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
const nestedId = tree.insert('nested/[id].vue') | ||
|
||
expect(nestedId.value.isParam()).toBe(true) | ||
|
@@ -86,7 +87,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('creates params in nested folders', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
|
||
let node = tree.insert('nested/[id]/index.vue') | ||
const id = tree.children.get('nested')!.children.get('[id]')! | ||
|
@@ -138,7 +139,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('handles repeatable params one or more', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[id]+.vue') | ||
expect(tree.children.get('[id]+')!.value).toMatchObject({ | ||
rawSegment: '[id]+', | ||
|
@@ -156,7 +157,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('handles repeatable params zero or more', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[[id]]+.vue') | ||
expect(tree.children.get('[[id]]+')!.value).toMatchObject({ | ||
rawSegment: '[[id]]+', | ||
|
@@ -174,7 +175,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('handles optional params', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[[id]].vue') | ||
expect(tree.children.get('[[id]]')!.value).toMatchObject({ | ||
rawSegment: '[[id]]', | ||
|
@@ -192,7 +193,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('handles named views', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('index.vue') | ||
tree.insert('[email protected]') | ||
tree.insert('[email protected]') | ||
|
@@ -233,15 +234,15 @@ describe('Tree', () => { | |
}) | ||
|
||
it('handles single named views that are not default', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[email protected]') | ||
expect([...tree.children.get('index')!.value.components.keys()]).toEqual([ | ||
'a', | ||
]) | ||
}) | ||
|
||
it('removes the node after all named views', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('index.vue') | ||
tree.insert('[email protected]') | ||
expect(tree.children.get('index')).toBeDefined() | ||
|
@@ -252,7 +253,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('can remove itself from the tree', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('index.vue').insert('nested.vue') | ||
tree.insert('a.vue').insert('nested.vue') | ||
tree.insert('b.vue') | ||
|
@@ -264,7 +265,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('handles multiple params', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[a]-[b].vue') | ||
tree.insert('o[a]-[b]c.vue') | ||
tree.insert('o[a][b]c.vue') | ||
|
@@ -276,7 +277,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('creates a tree of nested routes', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('index.vue') | ||
tree.insert('a/index.vue') | ||
tree.insert('a/b/index.vue') | ||
|
@@ -313,7 +314,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('handles a modifier for single params', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('[id]+.vue') | ||
expect(tree.children.size).toBe(1) | ||
const child = tree.children.get('[id]+')! | ||
|
@@ -329,7 +330,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('removes nodes', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('foo.vue') | ||
tree.insert('[id].vue') | ||
tree.remove('foo.vue') | ||
|
@@ -346,15 +347,15 @@ describe('Tree', () => { | |
}) | ||
|
||
it('removes empty folders', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('a/b/c/d.vue') | ||
expect(tree.children.size).toBe(1) | ||
tree.remove('a/b/c/d.vue') | ||
expect(tree.children.size).toBe(0) | ||
}) | ||
|
||
it('insert returns the node', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
const a = tree.insert('a.vue') | ||
expect(tree.children.get('a')).toBe(a) | ||
const bC = tree.insert('b/c.vue') | ||
|
@@ -366,7 +367,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('keeps parent with file but no children', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('a/b/c/d.vue') | ||
tree.insert('a/b.vue') | ||
expect(tree.children.size).toBe(1) | ||
|
@@ -381,7 +382,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('allows a custom name', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
let node = tree.insert('[a]-[b].vue') | ||
node.value.setOverride('', { | ||
name: 'custom', | ||
|
@@ -396,7 +397,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('allows a custom path', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
let node = tree.insert('[a]-[b].vue') | ||
node.value.setOverride('', { | ||
path: '/custom', | ||
|
@@ -413,7 +414,7 @@ describe('Tree', () => { | |
}) | ||
|
||
it('removes trailing slash from path but not from name', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('a/index.vue') | ||
tree.insert('a/a.vue') | ||
let child = tree.children.get('a')! | ||
|
@@ -435,7 +436,7 @@ describe('Tree', () => { | |
|
||
it('handles long extensions', () => { | ||
const tree = new PrefixTree({ | ||
...DEFAULT_OPTIONS, | ||
...RESOLVED_OPTIONS, | ||
extensions: ['.page.vue'], | ||
}) | ||
tree.insert('a.page.vue') | ||
|
@@ -467,7 +468,7 @@ describe('Tree', () => { | |
|
||
describe('dot nesting', () => { | ||
it('transforms dots into nested routes by default', () => { | ||
const tree = new PrefixTree(DEFAULT_OPTIONS) | ||
const tree = new PrefixTree(RESOLVED_OPTIONS) | ||
tree.insert('users.new.vue') | ||
expect(tree.children.size).toBe(1) | ||
const users = tree.children.get('users.new')! | ||
|
@@ -481,7 +482,7 @@ describe('Tree', () => { | |
|
||
it('can ignore dot nesting', () => { | ||
const tree = new PrefixTree({ | ||
...DEFAULT_OPTIONS, | ||
...RESOLVED_OPTIONS, | ||
pathParser: { | ||
dotNesting: false, | ||
}, | ||
|
Oops, something went wrong.