-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
399cffe
commit db5ed45
Showing
10 changed files
with
218 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const DEFAULT_DIRECTORY = 'test'; | ||
|
||
function getDirectory(rc) { | ||
|
||
if (!(typeof rc === 'object' && rc.directory)) { | ||
return DEFAULT_DIRECTORY; | ||
} | ||
|
||
const dir = rc.directory; | ||
const last = dir.substring(dir.length - 1); | ||
|
||
// strip trailing slashes | ||
if (last === '/' || last === '\\') { | ||
return dir.substring(0, dir.length - 1); | ||
} | ||
|
||
return dir; | ||
} | ||
|
||
function checkDirectory(dir) { | ||
|
||
dir = path.resolve(dir); | ||
try { | ||
fs.accessSync(dir, fs.F_OK); | ||
} catch (e) { // eslint-disable-next-line max-len | ||
e.message = `(clutch-assert/loader) Tried to instrument ${dir} but it does not exist. | ||
Please specify the correct directory in .clutchrc as follows: | ||
{ | ||
"directory": "test-unit" | ||
} | ||
`; | ||
throw e; | ||
} | ||
|
||
} | ||
|
||
function createPattern(dir) { | ||
return dir + path.sep + '**' + path.sep + '*.js'; | ||
} | ||
|
||
module.exports = {getDirectory, checkDirectory, createPattern}; |
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,34 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const helpers = require('./helpers'); | ||
const espower = require('espower-loader'); | ||
const patterns = require('../lib/patterns'); | ||
|
||
const parent = path.dirname(module.parent.paths[0]); | ||
|
||
var rc; | ||
try { | ||
rc = JSON.parse(fs.readFileSync(parent + path.sep + '.clutchrc')); | ||
} catch (e) { | ||
|
||
if (e.code !== 'ENOENT') { | ||
throw e; | ||
} | ||
|
||
// no clutchrc found | ||
|
||
} | ||
|
||
const dir = helpers.getDirectory(rc); | ||
helpers.checkDirectory(dir); | ||
const pattern = helpers.createPattern(dir); | ||
|
||
espower({ | ||
pattern, | ||
cwd: process.cwd(), | ||
espowerOptions: { | ||
patterns: patterns.ENHANCED, | ||
}, | ||
}); |
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,9 @@ | ||
'use strict'; | ||
|
||
// espower will replace the following with | ||
// const assert = require('power-assert'); | ||
|
||
const assert = require('assert'); | ||
const one = 1; | ||
|
||
assert.not(one, 1); |
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 @@ | ||
garbage |
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,20 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable global-require */ | ||
|
||
const test = require('ava'); | ||
|
||
test.afterEach(function() { | ||
|
||
delete require.cache[require.resolve('../../loader')]; | ||
}); | ||
|
||
test('does not swallow errors', function(t) { | ||
|
||
const err = t.throws(function() { | ||
require('../../loader'); | ||
}, SyntaxError); | ||
|
||
|
||
t.true(err.message.includes('Unexpected token g')); | ||
}); |
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,3 @@ | ||
{ | ||
"directory":"test/fixtures" | ||
} |
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,37 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'); | ||
const {sep} = require('path'); | ||
const helpers = require('../../loader/helpers'); | ||
|
||
test('getDirectory', t => { | ||
|
||
t.is(helpers.getDirectory(), 'test'); | ||
t.is(helpers.getDirectory(), 'test'); | ||
t.is(helpers.getDirectory('other'), 'test'); | ||
t.is(helpers.getDirectory({directory: 'other'}), 'other'); | ||
t.is(helpers.getDirectory({directory: 'other\\'}), 'other'); | ||
t.is(helpers.getDirectory({directory: 'other/'}), 'other'); | ||
|
||
}); | ||
|
||
test('checkDirectory', function(t) { | ||
|
||
t.notThrows(function() { | ||
helpers.checkDirectory('lib'); | ||
}); | ||
|
||
const err = t.throws(function() { | ||
helpers.checkDirectory('what'); | ||
}); | ||
|
||
t.true(err.message.includes('what')); | ||
|
||
}); | ||
|
||
|
||
test('createPattern', function(t) { | ||
|
||
t.is(helpers.createPattern('mytestdir'), `mytestdir${sep}**${sep}*.js`); | ||
|
||
}); |
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,21 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable global-require */ | ||
|
||
const test = require('ava'); | ||
|
||
test.afterEach(function() { | ||
delete require.cache[require.resolve('../../loader')]; | ||
}); | ||
|
||
test('overall', function(t) { | ||
|
||
require('../../loader'); | ||
|
||
const err = t.throws(function() { | ||
require('../fixtures/to_be_instrumented'); | ||
}); | ||
|
||
t.is(err.message, "Cannot find module 'power-assert'"); | ||
|
||
}); |