-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4f5b68
commit a683c04
Showing
2 changed files
with
33 additions
and
25 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 |
---|---|---|
@@ -1,31 +1,22 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import { loadTestFiles } from './loadTestFiles'; | ||
import { defaultParserOptions, defaultResolveOptions } from '../src/index'; | ||
import { extractComponent } from '../src/babel/extract-component'; | ||
|
||
describe('extract-component', () => { | ||
const folderName = path.join(__dirname, 'examples', 'extract-component'); | ||
const fileNames = fs.readdirSync(folderName); | ||
// .filter(fn => fn === 'node-modules-source.js'); | ||
fileNames.forEach(file => { | ||
const fileName = path.join(folderName, file); | ||
it(file, async () => { | ||
expect( | ||
await extractComponent('Button', fileName, undefined, { | ||
parser: defaultParserOptions, | ||
resolve: defaultResolveOptions, | ||
component: { | ||
resolveFile: (componentName: string, filePath: string) => { | ||
if (filePath.includes('/theme-ui/dist')) { | ||
return `${ | ||
filePath.split('/theme-ui/dist')[0] | ||
}/@theme-ui/components/src/${componentName}.js`; | ||
} | ||
return filePath; | ||
}, | ||
}, | ||
}), | ||
).toMatchSnapshot(); | ||
loadTestFiles(async (fileName: string) => { | ||
return await extractComponent('Button', fileName, undefined, { | ||
parser: defaultParserOptions, | ||
resolve: defaultResolveOptions, | ||
component: { | ||
resolveFile: (componentName: string, filePath: string) => { | ||
if (filePath.includes('/theme-ui/dist')) { | ||
return `${ | ||
filePath.split('/theme-ui/dist')[0] | ||
}/@theme-ui/components/src/${componentName}.js`; | ||
} | ||
return filePath; | ||
}, | ||
}, | ||
}); | ||
}); | ||
}, 'extract-component'); | ||
}); |
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,17 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
export type LoadTestCallbackFn = (fileName: string) => any; | ||
|
||
export const loadTestFiles = (callback: LoadTestCallbackFn, ...rest) => { | ||
const folderName = path.join(__dirname, 'examples', ...rest); | ||
const fileNames = fs.readdirSync(folderName); | ||
|
||
// .filter(fn => fn === 'node-modules-source.js'); | ||
fileNames.forEach(file => { | ||
const fileName = path.join(folderName, file); | ||
it(file, async () => { | ||
expect(await callback(fileName)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}; |