-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(build): Use babel instead of tsc for transpiling.
Signed-off-by: Jesse Stuart <hi@jessestuart.com>
- Loading branch information
1 parent
ce5a4df
commit 0aaf04f
Showing
12 changed files
with
495 additions
and
150 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
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
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 @@ | ||
module.exports = { | ||
sourceRoot: 'src/', | ||
ignore: ['./src/__tests__/*'], | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
// For more info on babel + core-js v3, | ||
// @see https://babeljs.io/blog/2019/03/19/7.4.0 | ||
useBuiltIns: 'usage', | ||
corejs: 3, | ||
}, | ||
], | ||
'@babel/preset-typescript', | ||
'minify', | ||
], | ||
} |
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,6 +1,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testRegex: '(/__tests__/.*\\.([tj]sx?)|(\\.|/)(test|spec))\\.([tj]sx?)$', | ||
testRegex: '(/__tests__/.*\\.([t]sx?)|(\\.|/)(test|spec))\\.([t]sx?)$', | ||
transform: { '^.+\\.tsx?$': 'ts-jest' }, | ||
} |
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
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,55 +1,59 @@ | ||
import sourceFilesystem from 'gatsby-source-filesystem' | ||
|
||
import Mitm from 'mitm' | ||
import configureMockStore from 'redux-mock-store' | ||
|
||
import { sourceNodes } from '../source-nodes' | ||
import fixtures from './fixtures.json' | ||
|
||
const mockStore = configureMockStore() | ||
import sourceFilesystem from 'gatsby-source-filesystem'; | ||
import _ from 'lodash'; | ||
import Mitm from 'mitm'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { sourceNodes } from '../source-nodes'; | ||
import fixtures from './fixtures.json'; | ||
|
||
// Mock out Gatby's source-filesystem API. | ||
sourceFilesystem.createRemoteFileNode = jest.fn() | ||
|
||
// Mock out `aws-sdk` module to prevent unnecessary calls to S3 during testing. | ||
jest.mock('aws-sdk', () => ({ | ||
S3: class { | ||
public listObjectsV2() { | ||
return { | ||
promise: () => fixtures, | ||
} | ||
} | ||
public listObjectsV2 = (..._: any[]) => ({ promise: () => fixtures }) | ||
}, | ||
})) | ||
|
||
describe('source S3ImageAsset nodes', () => { | ||
let args | ||
describe('Source S3ImageAsset nodes.', () => { | ||
let nodes = {} | ||
|
||
beforeEach(() => { | ||
args = { | ||
actions: { | ||
createNode: jest.fn(node => (nodes[node.id] = node)), | ||
}, | ||
cache: { | ||
get: jest.fn(), | ||
set: jest.fn(), | ||
}, | ||
createContentDigest: jest.fn(), | ||
createNodeId: jest.fn(), | ||
store: mockStore, | ||
} | ||
Mitm().on('request', () => { | ||
throw new Error('Network requests forbidden in offline mode.') | ||
let mockStore = {} | ||
|
||
const sourceNodeArgs = { | ||
actions: { | ||
createNode: jest.fn(node => (nodes[node.id] = node)), | ||
}, | ||
cache: { | ||
get: jest.fn(), | ||
set: jest.fn(), | ||
}, | ||
createContentDigest: jest.fn(), | ||
createNodeId: jest.fn(), | ||
store: mockStore, | ||
} | ||
|
||
beforeAll(() => { | ||
mockStore = configureMockStore() | ||
|
||
Mitm().on('request', req => { | ||
const host = _.get(req, 'headers.host') | ||
const url = _.get(req, 'url') | ||
throw new Error( | ||
`Network requests forbidden in offline mode. Tried to call URL "${host}${url}"` | ||
) | ||
}) | ||
}) | ||
|
||
test('sourceNodes', async () => { | ||
test('Verify sourceNodes creates the correct # of nodes, given our fixtures.', async () => { | ||
// NB: pulls from fixtures defined above, not S3 API. | ||
const entityNodes = await sourceNodes(args, { bucketName: 'fake-bucket' }) | ||
const entityNodes = await sourceNodes(sourceNodeArgs, { | ||
bucketName: 'fake-bucket', | ||
}) | ||
// `createRemoteFileNode` called once for each of the five images in fixtures. | ||
expect(sourceFilesystem.createRemoteFileNode).toHaveBeenCalledTimes(5) | ||
// 5 images + 2 directories = 7 nodes | ||
expect(entityNodes).toHaveLength(7) | ||
}) | ||
|
||
// TODO | ||
test('Verify getNodeEntityFields utils func.', () => {}) | ||
}) |
Oops, something went wrong.