Skip to content

Commit

Permalink
feat: load test files from examples
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 7, 2020
1 parent d4f5b68 commit a683c04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
41 changes: 16 additions & 25 deletions core/instrument/test/extract-component.test.ts
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');
});
17 changes: 17 additions & 0 deletions core/instrument/test/loadTestFiles.ts
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();
});
});
};

0 comments on commit a683c04

Please sign in to comment.