-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make new group for .ts links
- Loading branch information
1 parent
b36bbb3
commit 2ac278d
Showing
1 changed file
with
89 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,55 +149,6 @@ test.group('Views Linker | .edge', () => { | |
`) | ||
}) | ||
|
||
test('ts source type', async ({ assert, fs }) => { | ||
await fs.create('resources/views/components/button.edge', '') | ||
await fs.create('resources/views/pages/admin.edge', '') | ||
|
||
const indexer = new TemplateIndexer({ | ||
rootPath: fs.basePath, | ||
disks: { default: 'resources/views' }, | ||
}) | ||
await indexer.scan() | ||
|
||
const template = dedent` | ||
return view.render('components/button', { | ||
props: 42 | ||
}) | ||
return view.renderSync('pages/admin', {}) | ||
` | ||
|
||
const result = await Linker.getLinks({ | ||
fileContent: template, | ||
indexer, | ||
sourceType: 'ts', | ||
}) | ||
|
||
const positions = result.map((r) => r.position) | ||
|
||
assert.snapshot(positions).matchInline(` | ||
[ | ||
{ | ||
"colEnd": 37, | ||
"colStart": 20, | ||
"line": 0, | ||
}, | ||
{ | ||
"colEnd": 35, | ||
"colStart": 24, | ||
"line": 4, | ||
}, | ||
] | ||
`) | ||
|
||
const paths = result.map((r) => r.templatePath) | ||
|
||
assert.sameDeepMembers(paths, [ | ||
slash(join(indexer.project.rootPath, 'resources/views/components/button.edge')), | ||
slash(join(indexer.project.rootPath, 'resources/views/pages/admin.edge')), | ||
]) | ||
}) | ||
|
||
test('should not detect internal tags as components', async ({ assert, fs }) => { | ||
const template = dedent` | ||
@if(true) | ||
|
@@ -339,21 +290,51 @@ test.group('Views Linker | .edge', () => { | |
assert.deepEqual(positions, [{ colEnd: 29, colStart: 12, line: 3 }]) | ||
}) | ||
|
||
test('match template in ts file in correct position', async ({ assert, fs }) => { | ||
test('should find link even when the component props include "(" character', async ({ | ||
assert, | ||
fs, | ||
}) => { | ||
await fs.create('resources/views/components/button.edge', '') | ||
|
||
const template = dedent` | ||
@!button('foo', { test: route('bar') }) | ||
` | ||
|
||
const indexer = new TemplateIndexer({ | ||
rootPath: fs.basePath, | ||
disks: { default: 'resources/views' }, | ||
}) | ||
|
||
await indexer.scan() | ||
|
||
const template = dedent` | ||
console.log('components/button') | ||
const result = await Linker.getLinks({ | ||
fileContent: template, | ||
indexer, | ||
sourceType: 'edge', | ||
}) | ||
|
||
const positions = result.map((r) => r.position) | ||
assert.deepEqual(positions, [{ colEnd: 8, colStart: 2, line: 0 }]) | ||
}) | ||
}) | ||
|
||
test.group('Views Linker | .ts', () => { | ||
test('ts source type', async ({ assert, fs }) => { | ||
await fs.create('resources/views/components/button.edge', '') | ||
await fs.create('resources/views/pages/admin.edge', '') | ||
|
||
const indexer = new TemplateIndexer({ | ||
rootPath: fs.basePath, | ||
disks: { default: 'resources/views' }, | ||
}) | ||
await indexer.scan() | ||
|
||
const template = dedent` | ||
return view.render('components/button', { | ||
props: 42 | ||
}) | ||
return view.renderSync('pages/admin', {}) | ||
` | ||
|
||
const result = await Linker.getLinks({ | ||
|
@@ -363,33 +344,78 @@ test.group('Views Linker | .edge', () => { | |
}) | ||
|
||
const positions = result.map((r) => r.position) | ||
assert.deepEqual(positions, [{ colEnd: 37, colStart: 20, line: 2 }]) | ||
}) | ||
|
||
test('should find link even when the component props include "(" character', async ({ | ||
assert, | ||
fs, | ||
}) => { | ||
await fs.create('resources/views/components/button.edge', '') | ||
assert.snapshot(positions).matchInline(` | ||
[ | ||
{ | ||
"colEnd": 37, | ||
"colStart": 20, | ||
"line": 0, | ||
}, | ||
{ | ||
"colEnd": 35, | ||
"colStart": 24, | ||
"line": 4, | ||
}, | ||
] | ||
`) | ||
|
||
const template = dedent` | ||
@!button('foo', { test: route('bar') }) | ||
const paths = result.map((r) => r.templatePath) | ||
|
||
assert.sameDeepMembers(paths, [ | ||
slash(join(indexer.project.rootPath, 'resources/views/components/button.edge')), | ||
slash(join(indexer.project.rootPath, 'resources/views/pages/admin.edge')), | ||
]) | ||
}) | ||
|
||
test('should not mark emails as components', async ({ assert, fs }) => { | ||
const template = ` | ||
router.get('/send-email', async ({ response, session }) => { | ||
message.from('[email protected]') | ||
.text('Hello world') | ||
.to('[email protected]').subject('My subject') | ||
}) | ||
` | ||
|
||
const indexer = new TemplateIndexer({ | ||
rootPath: fs.basePath, | ||
disks: { default: 'resources/views' }, | ||
}) | ||
await indexer.scan() | ||
|
||
const result = await Linker.getLinks({ | ||
fileContent: template, | ||
indexer, | ||
sourceType: 'ts', | ||
}) | ||
|
||
assert.deepEqual(result, []) | ||
}) | ||
|
||
test('match template in ts file in correct position', async ({ assert, fs }) => { | ||
await fs.create('resources/views/components/button.edge', '') | ||
|
||
const indexer = new TemplateIndexer({ | ||
rootPath: fs.basePath, | ||
disks: { default: 'resources/views' }, | ||
}) | ||
await indexer.scan() | ||
|
||
const template = dedent` | ||
console.log('components/button') | ||
return view.render('components/button', { | ||
props: 42 | ||
}) | ||
` | ||
|
||
const result = await Linker.getLinks({ | ||
fileContent: template, | ||
indexer, | ||
sourceType: 'edge', | ||
sourceType: 'ts', | ||
}) | ||
|
||
const positions = result.map((r) => r.position) | ||
assert.deepEqual(positions, [{ colEnd: 8, colStart: 2, line: 0 }]) | ||
assert.deepEqual(positions, [{ colEnd: 37, colStart: 20, line: 2 }]) | ||
}) | ||
}) |