Skip to content

Commit

Permalink
test(preset): add test cases for deps analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Apr 20, 2020
1 parent 6c636ad commit f51fd29
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { common } from '.';

export default () => common;
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();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './multi';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as yaml } from 'js-yaml';
export default 'last';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './last';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './level';
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>
</>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'normal';
41 changes: 41 additions & 0 deletions packages/preset-dumi/src/transformer/test/demo-deps.test.ts
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();
});
});

0 comments on commit f51fd29

Please sign in to comment.