Skip to content

Commit

Permalink
test(paths): Resolve paths properly within tests
Browse files Browse the repository at this point in the history
Use `path.resolve` instead of to manually joining
strings with OS-specific path separator.
  • Loading branch information
gtramontina committed Jul 4, 2016
1 parent 861a4c5 commit bcfea36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
3 changes: 2 additions & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"globals": {
"proxyquire": false,
"fsStub": false
"fsStub": false,
"path": false
}
}
11 changes: 3 additions & 8 deletions test/hook.template.raw.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
})

it('delegates the hook execution to ghooks', () => {
const dirname = process.cwd() + '/lib'
const filename = dirname + '/hook.template.raw'
const filename = path.resolve(process.cwd(), 'lib', 'hook.template.raw')
expect(this.ghooks).to.have.been.calledWith('{{node_modules_path}}', filename)
})

Expand All @@ -29,15 +28,13 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
describe('when ghooks is installed, but the node working dir is below the project dir', () => {

beforeEach(() => {
const path = require('path')
const ghooksEntryPoint = path.resolve(__dirname, '..', '{{node_modules_path}}', 'ghooks')
this.ghooks = sinon.stub()
proxyquire('../lib/hook.template.raw', {ghooks: null, [ghooksEntryPoint]: this.ghooks})
})

it('delegates the hook execution to ghooks', () => {
const dirname = process.cwd() + '/lib'
const filename = dirname + '/hook.template.raw'
const filename = path.resolve(process.cwd(), 'lib', 'hook.template.raw')
expect(this.ghooks).to.have.been.calledWith('{{node_modules_path}}', filename)
})

Expand All @@ -46,7 +43,6 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
describe('when ghooks is installed, using worktree / in a submodule', () => {

beforeEach(() => {
const path = require('path')
const worktree = '../../a/path/somewhere/else'
const ghooksResolved = path.resolve(process.cwd(), worktree, 'node_modules', 'ghooks')
const stub = {
Expand All @@ -63,8 +59,7 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
})

it('delegates the hook execution to ghooks', () => {
const dirname = process.cwd() + '/lib'
const filename = dirname + '/hook.template.raw'
const filename = path.resolve(process.cwd(), 'lib', 'hook.template.raw')
expect(this.ghooks).to.have.been.calledWith('{{node_modules_path}}', filename)
})

Expand Down
1 change: 1 addition & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ global.expect = chai.expect
global.sinon = require('sinon')
global.fsStub = require('mock-fs')
global.proxyquire = require('proxyquire').noCallThru()
global.path = require('path')

module.exports = function restore() {
afterEach(fsStub.restore)
Expand Down

0 comments on commit bcfea36

Please sign in to comment.