Skip to content

Commit 0a98cbf

Browse files
committed
test: Add Unit Test
1 parent f0c71fa commit 0a98cbf

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
dist: trusty
2+
before_install:
3+
- npm install -g npm@latest
4+
language: node_js
5+
node_js:
6+
- "0.10"
7+
- "3.3"
8+
- "4.2"
9+
- "5.0"
10+
script:
11+
- npm run test
12+
after_success:
13+
- curl -Lo travis_after_all.py https://raw.githubusercontent.com/contentful/travis_after_all/master/travis_after_all.py
14+
- python travis_after_all.py
15+
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
16+
- export $(cat .to_export_back) &> /dev/null
17+
- npm run semantic-release

test/run-contentful-import-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import test from 'tape'
2+
import sinon from 'sinon'
3+
import runContentfulImport from '../lib/run-contentful-import'
4+
import Promise from 'bluebird'
5+
const createClientsStub = sinon.stub().returns({ source: {delivery: {}}, destination: {management: {}} })
6+
runContentfulImport.__Rewire__('createClients', createClientsStub)
7+
const getTransformedDestinationResponse = sinon.stub().returns(
8+
Promise.resolve({contentTypes: [], entries: [], assets: [], locales: []})
9+
)
10+
runContentfulImport.__Rewire__('getTransformedDestinationResponse', getTransformedDestinationResponse)
11+
12+
const transformSpaceStub = sinon.stub().returns(Promise.resolve({contentTypes: [], entries: [], assets: [], locales: []}))
13+
runContentfulImport.__Rewire__('transformSpace', transformSpaceStub)
14+
const pushToSpaceStub = sinon.stub().returns(Promise.resolve({}))
15+
runContentfulImport.__Rewire__('pushToSpace', pushToSpaceStub)
16+
test('Runs Contentful Import', (t) => {
17+
runContentfulImport({
18+
opts: {},
19+
errorLogFile: 'errorlogfile'
20+
})
21+
.then(() => {
22+
t.ok(createClientsStub.called, 'create clients')
23+
t.ok(transformSpaceStub.called, 'transform space')
24+
t.ok(pushToSpaceStub.called, 'push to space')
25+
runContentfulImport.__ResetDependency__('createClients')
26+
runContentfulImport.__ResetDependency__('transformSpace')
27+
runContentfulImport.__ResetDependency__('pushToSpace')
28+
t.end()
29+
})
30+
})
31+

test/runner

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
var log = require('npmlog')
3+
log.level = 'silent'
4+
5+
require('require-all')({
6+
dirname: process.cwd() + '/test',
7+
filter: process.argv[2] || /\-test\.js$/,
8+
recursive: true
9+
})

0 commit comments

Comments
 (0)