-
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.
feat(tests): Basic test coverage for sourceNodes integration.
Signed-off-by: Jesse Stuart <hi@jessestuart.com>
- Loading branch information
1 parent
467ce51
commit 85ed2d3
Showing
11 changed files
with
252 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
threshold: 30% | ||
patch: | ||
default: | ||
target: 50% | ||
only_pulls: true |
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,4 +1,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testRegex: '(/__tests__/.*\\.([tj]sx?)|(\\.|/)(test|spec))\\.([tj]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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"IsTruncated": false, | ||
"Contents": [ | ||
{ | ||
"Key": "2017-12-25/", | ||
"LastModified": "2018-02-15T09:55:23.000Z", | ||
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"", | ||
"Size": 0, | ||
"StorageClass": "STANDARD" | ||
}, | ||
{ | ||
"Key": "2017-12-25/_DSC7589.jpg", | ||
"LastModified": "2018-02-15T09:55:25.000Z", | ||
"ETag": "\"8ed1dc689c7baeba0cf0196037ac70c0\"", | ||
"Size": 900211, | ||
"StorageClass": "STANDARD" | ||
}, | ||
{ | ||
"Key": "2019-04-10/", | ||
"LastModified": "2019-04-11T02:54:23.000Z", | ||
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"", | ||
"Size": 0, | ||
"StorageClass": "STANDARD" | ||
}, | ||
{ | ||
"Key": "2019-04-10/DSC02621.jpg", | ||
"LastModified": "2019-04-11T02:59:06.000Z", | ||
"ETag": "\"921da2f4adcf76e0d02719bb2696cc58\"", | ||
"Size": 15285486, | ||
"StorageClass": "STANDARD" | ||
}, | ||
{ | ||
"Key": "2019-04-10/DSC02943.jpg", | ||
"LastModified": "2019-04-11T02:54:39.000Z", | ||
"ETag": "\"833816655f9709cb1b2b8ac9505a3c65\"", | ||
"Size": 7275401, | ||
"StorageClass": "STANDARD" | ||
}, | ||
{ | ||
"Key": "2019-04-10/DSC02943.jpg", | ||
"LastModified": "2019-04-11T02:54:39.000Z", | ||
"ETag": "\"833816659f9709cb1b2b8ac9505a3c65\"", | ||
"Size": 7275401, | ||
"StorageClass": "STANDARD" | ||
}, | ||
{ | ||
"Key": "2019-04-10/DSC02943.jpg", | ||
"LastModified": "2019-04-11T02:54:39.000Z", | ||
"ETag": "\"833816660f9709cb1b2b8ac9505a3c65\"", | ||
"Size": 7275401, | ||
"StorageClass": "STANDARD" | ||
} | ||
], | ||
"Name": "js-photos-dev", | ||
"Prefix": "", | ||
"MaxKeys": 1000, | ||
"CommonPrefixes": [], | ||
"KeyCount": 5 | ||
} |
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,70 @@ | ||
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() | ||
|
||
// Mock out Gatby's source-filesystem API. | ||
sourceFilesystem.createRemoteFileNode = jest.fn().mockImplementation(node => { | ||
console.log({ node }) | ||
}) | ||
|
||
// Mock out `aws-sdk` module to prevent unnecessary calls to S3 during testing. | ||
jest.mock('aws-sdk', () => ({ | ||
S3: class { | ||
public listObjectsV2() { | ||
return { | ||
promise: () => fixtures, | ||
} | ||
} | ||
}, | ||
})) | ||
|
||
describe('source S3ImageAsset nodes', () => { | ||
let args | ||
let nodes = {} | ||
|
||
beforeEach(() => { | ||
spyOn(sourceFilesystem, 'createRemoteFileNode') | ||
args = { | ||
actions: { | ||
createNode: jest.fn(node => (nodes[node.id] = node)), | ||
}, | ||
cache: { | ||
get: jest.fn(), | ||
set: jest.fn(), | ||
}, | ||
createContentDigest: jest.fn(), | ||
createNodeId: jest.fn().mockImplementation(node => { | ||
console.log('create node ID', { node }) | ||
return node | ||
}), | ||
store: mockStore, | ||
} | ||
Mitm().on('request', () => { | ||
throw new Error('Network requests forbidden in offline mode.') | ||
}) | ||
}) | ||
|
||
test('sourceNodes', async () => { | ||
// NB: pulls from fixtures defined above, not S3 API. | ||
const entityNodes = await sourceNodes(args, { 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) | ||
}) | ||
|
||
test('createS3ImageAssetNode', async () => { | ||
// NB: pulls from fixtures defined above, not S3 API. | ||
const entityNodes = await sourceNodes(args, { 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) | ||
}) | ||
}) |
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
Oops, something went wrong.