forked from umijs/dumi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(preset): add test cases for deps analyzer
- Loading branch information
1 parent
6c636ad
commit f51fd29
Showing
9 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/preset-dumi/src/transformer/fixtures/demo-deps/circular/circular.ts
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { common } from '.'; | ||
|
||
export default () => common; |
6 changes: 6 additions & 0 deletions
6
packages/preset-dumi/src/transformer/fixtures/demo-deps/circular/index.ts
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import yaml from 'js-yaml'; | ||
import circular from './circular'; | ||
|
||
export const common = typeof yaml; | ||
|
||
export default () => circular(); |
1 change: 1 addition & 0 deletions
1
packages/preset-dumi/src/transformer/fixtures/demo-deps/multi-levels/index.ts
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './multi'; |
2 changes: 2 additions & 0 deletions
2
packages/preset-dumi/src/transformer/fixtures/demo-deps/multi-levels/last.ts
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as yaml } from 'js-yaml'; | ||
export default 'last'; |
1 change: 1 addition & 0 deletions
1
packages/preset-dumi/src/transformer/fixtures/demo-deps/multi-levels/level.ts
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './last'; |
1 change: 1 addition & 0 deletions
1
packages/preset-dumi/src/transformer/fixtures/demo-deps/multi-levels/multi.ts
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './level'; |
9 changes: 9 additions & 0 deletions
9
packages/preset-dumi/src/transformer/fixtures/demo-deps/normal/index.tsx
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import yaml from 'js-yaml'; | ||
import normal from './normal'; | ||
|
||
export default () => ( | ||
<> | ||
<h1>{typeof yaml}</h1> | ||
<p>{normal}</p> | ||
</> | ||
) |
1 change: 1 addition & 0 deletions
1
packages/preset-dumi/src/transformer/fixtures/demo-deps/normal/normal.ts
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'normal'; |
41 changes: 41 additions & 0 deletions
41
packages/preset-dumi/src/transformer/test/demo-deps.test.ts
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import analyzeDeps from '../demo/dependencies'; | ||
|
||
describe('demo transformer: dependencies', () => { | ||
it('basic analysis', () => { | ||
const filePath = path.join(__dirname, '../fixtures/demo-deps/normal/index.tsx'); | ||
const result = analyzeDeps(fs.readFileSync(filePath).toString(), { | ||
isTSX: true, | ||
fileAbsPath: filePath, | ||
}); | ||
|
||
expect(result.files['normal.ts']).not.toBeUndefined(); | ||
expect(result.dependencies['js-yaml']).not.toBeUndefined(); | ||
}); | ||
|
||
it('multi level', () => { | ||
const filePath = path.join(__dirname, '../fixtures/demo-deps/multi-levels/index.ts'); | ||
const result = analyzeDeps(fs.readFileSync(filePath).toString(), { | ||
isTSX: false, | ||
fileAbsPath: filePath, | ||
}); | ||
|
||
expect(result.files['multi.ts']).not.toBeUndefined(); | ||
expect(result.files['level.ts']).not.toBeUndefined(); | ||
expect(result.files['last.ts']).not.toBeUndefined(); | ||
expect(result.dependencies['js-yaml']).not.toBeUndefined(); | ||
}); | ||
|
||
it('circular reference', () => { | ||
const filePath = path.join(__dirname, '../fixtures/demo-deps/circular/index.ts'); | ||
const result = analyzeDeps(fs.readFileSync(filePath).toString(), { | ||
isTSX: false, | ||
fileAbsPath: filePath, | ||
}); | ||
|
||
expect(result.files['circular.ts']).not.toBeUndefined(); | ||
expect(Object.keys(result.files).length).toEqual(1); | ||
expect(result.dependencies['js-yaml']).not.toBeUndefined(); | ||
}); | ||
}); |