Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Tests for dependency resolution
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 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,37 @@ | ||
var os = require('os'); | ||
var shell = require('shelljs'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var dependency = require('../../../src/input/dependency'); | ||
|
||
function inputs(contents) { | ||
var dirEntry = os.tmpdir(); | ||
var paths = {}; | ||
for (var filename in contents) { | ||
paths[filename] = path.join(dirEntry, '/', filename); | ||
fs.writeFileSync(paths[filename], contents[filename]); | ||
} | ||
return { | ||
paths | ||
}; | ||
} | ||
|
||
test('dependency', async function() { | ||
let { paths, cleanup } = inputs({ | ||
'index.js': 'module.exports = 1;', | ||
'requires.js': "module.exports = require('./foo');", | ||
'foo.js': 'module.exports = 2;' | ||
}); | ||
{ | ||
let dependencies = await dependency([paths['index.js']], { | ||
parseExtension: ['js'] | ||
}); | ||
expect(dependencies.length).toEqual(1); | ||
} | ||
{ | ||
let dependencies = await dependency([paths['requires.js']], { | ||
parseExtension: ['js'] | ||
}); | ||
expect(dependencies.length).toEqual(2); | ||
} | ||
}); |