-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest Test Suite Set-up and some tests #109
Changes from all commits
ad86030
6ff6ace
a1ba4f5
81b97dd
cc2dfb3
1c144c6
f380aa4
f7a8de3
849310d
fda70a8
83c421f
b640a43
b7d2d9f
2ecbd4d
dbb2f71
f757b4d
277c309
a989635
b24b106
775a7a1
c9b1f63
705242d
d7a581a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"presets": [ | ||
["es2015", { "modules" : false }] | ||
] | ||
], | ||
"env": { | ||
"test": { | ||
"presets": ["es2015"] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/node:8.9.3 | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: npm install | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
- run: | ||
name: Lint JS | ||
command: npm run lint | ||
- run: | ||
name: Run tests | ||
command: npm run test -- --maxWorkers=4 | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,13 @@ | |
"sourceType": "module", | ||
"ecmaVersion": 6 | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["src/**/*.js", "src/**/*.vue"], | ||
"excludedFiles": "*.test.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are tests excluded from eslint? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm linting for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm worried that this might lead to issues down the line, but 👍 for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to remember to lint test files again when we have decent test coverage |
||
} | ||
], | ||
|
||
// add global vars for chai, etc | ||
"globals": { | ||
"expect": false, | ||
|
@@ -66,7 +73,7 @@ | |
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], | ||
"space-infix-ops": [1, {"int32Hint": false}], | ||
"spaced-comment": [2, "always"], | ||
// es6 | ||
// avoid-escape6 | ||
"generator-star-spacing": [2, "before"], | ||
// legacy jshint rules | ||
"max-depth": [2, 4], | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
collectCoverage: true, | ||
collectCoverageFrom: ['src/services/*.js'], | ||
coverageReporters: ['text-summary'] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { addToSpace, findAvailableComponents} from './add-service.js'; | ||
import { kilnApiStub, VuexStoreStub } from '../../test/utils.js'; | ||
|
||
// importing these other services so we can mock them | ||
import * as createService from './create-service'; | ||
import * as utils from './utils'; | ||
import * as toggleService from './toggle-service'; | ||
|
||
describe('add-service', ()=>{ | ||
let dispatchCalls = [], storeStub; | ||
const spaceRef = '/_components/clay-space/instances/my-space', | ||
availableComponents = ['related-stories', 'ad', 'most-popular']; | ||
|
||
beforeEach(()=>{ | ||
storeStub = new VuexStoreStub(null, dispatchCalls); | ||
storeStub.state.components[spaceRef] = {content: [ | ||
{_ref: '/_components/space-logic/instances/space-logic-123'} | ||
]}; | ||
|
||
createService.findSpaceLogic = jest.fn() | ||
.mockReturnValue('space-logic'); | ||
|
||
utils.getAvailableComponents = jest.fn() | ||
.mockReturnValue(availableComponents); | ||
utils.findParentUriAndList = jest.fn() | ||
.mockReturnValue({el: 'layout', list:'teritary'}); | ||
|
||
toggleService.setNewActiveLogic = jest.fn(); | ||
|
||
global.kiln = kilnApiStub; | ||
global.kiln.utils.create.default = jest.fn() | ||
.mockReturnValue(Promise.resolve(['related-stories'])); | ||
// stubbing an empty object to this Kiln method to prevent errors | ||
global.kiln.utils.references.getComponentName = jest.fn(); | ||
|
||
}); | ||
|
||
it('fetch list of components that can be added to a Space', ()=>{ | ||
expect(findAvailableComponents(storeStub, spaceRef)).toBe(availableComponents); | ||
// make sure we are finding the correct parent | ||
expect(utils.findParentUriAndList).toBeCalledWith(spaceRef); | ||
}); | ||
|
||
describe('add Space Logic to Space', ()=>{ | ||
it('after adding a new Logic, that logic is set to active', ()=>{ | ||
return addToSpace(storeStub, spaceRef, 'related-stories') | ||
.then(()=>{ | ||
expect(toggleService.setNewActiveLogic).toBeCalledWith(storeStub, spaceRef); | ||
}); | ||
}); | ||
|
||
it('create a new instance of a Space Logic and add it to the Space', ()=>{ | ||
return addToSpace(storeStub, spaceRef, 'related-stories') | ||
.then(()=>{ | ||
const testDispatch = dispatchCalls[0]; | ||
|
||
expect(testDispatch.type).toBe('addComponents'); | ||
// make sure that we're adding the new Space Logic to the last Space | ||
// Logic in the Space | ||
expect(testDispatch.payload.currentURI).toBe('/_components/space-logic/instances/space-logic-123'); | ||
expect(testDispatch.payload.components[0].name).toBe('space-logic'); | ||
}); | ||
}); | ||
|
||
it('when adding a component to a Space, a new instances of that components should be created', ()=>{ | ||
|
||
return addToSpace(storeStub, spaceRef, 'related-stories') | ||
.then(()=>{ | ||
const testDispatch = dispatchCalls[0]; | ||
|
||
// are we creating the correct component? | ||
expect(global.kiln.utils.create.default).toBeCalledWith([{name: 'related-stories'}]); | ||
// ... then are we embedding it into the Space Logic? | ||
expect(testDispatch.payload.components[0].data).toEqual({ | ||
embeddedComponent: 'related-stories' | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, it looks like there's no env stuff being set in the
package.json
. Is this being called correctly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some digging and there's no need to set a babel
env
inpackage.json
because Jest will automatically set theenv
totest
if it's not provided (per the doc here).