Skip to content

Commit

Permalink
feat: refactoring the root index to no longer require fs
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed Dec 1, 2021
1 parent df35bcc commit 21fe4fe
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 12 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
node_modules/
src/*.har
index.js
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __tests__/
coverage/
.eslint*
.prettier*
build.js
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage/
src/*.har
index.js
6 changes: 6 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const toBeAValidHAR = require('jest-expect-har').default;

expect.extend({ toBeAValidHAR });

test('root export should load', () => {
// eslint-disable-next-line global-require
const root = require('..');
expect(root['application-json']).toBeDefined();
});

test('export should contain HARs', () => {
expect(Object.keys(hars).length).toBeGreaterThan(0);
});
Expand Down
22 changes: 22 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');

(async () => {
const out = {};
const files = await fs.readdirSync(path.join(__dirname, './src'));

files
.filter(har => {
return har.indexOf('.har') !== -1;
})
.forEach(har => {
out[har.replace('.har', '')] = JSON.parse(fs.readFileSync(path.join(__dirname, `./src/${har}`), 'utf8'));
});

const build = `// This file is autogenerated. Run \`npm run build\` to update it.
module.exports = ${JSON.stringify(out, undefined, 2)};`;

fs.writeFileSync('index.js', build);
})();
Loading

0 comments on commit 21fe4fe

Please sign in to comment.