Skip to content

Commit

Permalink
chore: add test framework (#42)
Browse files Browse the repository at this point in the history
Part of #38 and #11
  • Loading branch information
raae authored Sep 27, 2022
1 parent a18a9df commit c810e80
Show file tree
Hide file tree
Showing 6 changed files with 1,153 additions and 29 deletions.
5 changes: 5 additions & 0 deletions jest-preprocess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const babelOptions = {
presets: ['babel-preset-gatsby'],
};

module.exports = require('babel-jest').default.createTransformer(babelOptions);
19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
transform: {
'^.+\\.jsx?$': `<rootDir>/jest-preprocess.js`,
},
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss)$': `identity-obj-proxy`,
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `<rootDir>/__mocks__/file-mock.js`,
'^gatsby-page-utils/(.*)$': `gatsby-page-utils/dist/$1`, // Workaround for https://github.com/facebook/jest/issues/9771
},
testPathIgnorePatterns: [`node_modules`, `\\.cache`, `<rootDir>.*/public`],
transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],
globals: {
__PATH_PREFIX__: ``,
},
testEnvironmentOptions: {
url: `http://localhost`,
},
setupFiles: [`<rootDir>/loadershim.js`],
};
3 changes: 3 additions & 0 deletions loadershim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global.___loader = {
enqueue: jest.fn(),
};
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
"demo"
],
"scripts": {
"test": "jest --watch",
"develop": "yarn workspace demo develop",
"build": "yarn workspace demo build",
"serve": "yarn workspace demo serve",
"clean": "yarn workspace demo clean",
"format": "prettier --write \".\""
},
"devDependencies": {
"prettier": "^2.6.2"
"babel-jest": "29.0.3",
"babel-preset-gatsby": "2.23.0",
"gatsby-plugin-utils": "3.17.1",
"identity-obj-proxy": "3.0.0",
"jest": "29.0.3",
"prettier": "^2.6.2",
"react-test-renderer": "18.2.0"
}
}
21 changes: 21 additions & 0 deletions plugin/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getResourceOptions } from './utils';

describe('getResourceOptions', () => {
it('transforms options to snake case', () => {
const result = getResourceOptions({
resourceType: 'image',
prefix: 'demo/examples',
maxResults: 50,
});

const expected = {
resource_type: 'image',
prefix: 'demo/examples',
max_results: 50,
results_per_page: 50,
type: 'upload',
};

expect(result).toEqual(expected);
});
});
Loading

0 comments on commit c810e80

Please sign in to comment.