Anton Shchekota abb781a69a refactor: replace module-deps-sortable on own implementation to control how parse files
BREAKING CHANGE:
all Extensions whould contains '.' so that mean if you have just 'ts' then need to convert to '.ts'
2021-11-11 11:52:31 +03:00

37 lines
926 B
JavaScript

import os from 'os';
import path from 'path';
import fs from 'fs';
import dependency from '../../../src/input/dependency.js';
function inputs(contents) {
const dirEntry = os.tmpdir();
const paths = {};
for (const filename in contents) {
paths[filename] = path.join(dirEntry, '/', filename);
fs.writeFileSync(paths[filename], contents[filename]);
}
return {
paths
};
}
test('dependency', async function () {
const { paths, cleanup } = inputs({
'index.js': 'module.exports = 1;',
'requires.js': "module.exports = require('./foo');",
'foo.js': 'module.exports = 2;'
});
{
const dependencies = await dependency([paths['index.js']], {
parseExtension: ['.js']
});
expect(dependencies.length).toEqual(1);
}
{
const dependencies = await dependency([paths['requires.js']], {
parseExtension: ['.js']
});
expect(dependencies.length).toEqual(2);
}
});