Test getLayers
This commit is contained in:
parent
0548ae993c
commit
e7e2f02581
21
index.js
21
index.js
@ -99,6 +99,27 @@ function getLayers(fileName, tmpDir) {
|
||||
});
|
||||
}
|
||||
|
||||
function getLayers2(dir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Make sure the directory exists
|
||||
if (!fs.existsSync(dir)) {
|
||||
return reject(new Error('Layers folder does not exist.'));
|
||||
}
|
||||
// Check that the required layer files exist in source dir
|
||||
let layersValid = true;
|
||||
gerberFiles.forEach((layer) => {
|
||||
if (!fs.existsSync(path.join(dir, layer))) layersValid = false;
|
||||
});
|
||||
if (!layersValid) return reject(new Error('Layer not found.'));
|
||||
// Construct array of layers that match the supplied filenames array
|
||||
const layers = gerberFiles.map((layerName) => ({
|
||||
filename: layerName,
|
||||
gerber: fs.createReadStream(path.join(dir, layerName)),
|
||||
}));
|
||||
return resolve(layers);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the archive folder in the specified directory
|
||||
* @param {string} dir Path to a directory to clean up
|
||||
|
@ -6,6 +6,7 @@ const fileProc = require('../index.js');
|
||||
const testGerber = path.join(__dirname, 'Arduino-Pro-Mini.zip');
|
||||
const testLayers = path.join(__dirname, 'layers');
|
||||
const emptyFolder = path.join(__dirname, 'layers', 'Empty');
|
||||
const tmpDir = path.join(__dirname, 'tmp');
|
||||
|
||||
// getLayers
|
||||
test('Promise of an array of layers from a given folder', () => {
|
||||
@ -22,9 +23,9 @@ test('Promise of an array of layers from a given folder', () => {
|
||||
});
|
||||
|
||||
test('Non-existent folder should reject promise with error', () => {
|
||||
return expect(fileProc.getLayers2('./invalid_folder')).rejects.toThrow('Layers folder does not exist');
|
||||
return expect(fileProc.getLayers2('./invalid_folder')).rejects.toThrow('Layers folder does not exist.');
|
||||
});
|
||||
|
||||
test('Folder with incorrect number of layers should reject promise with error', () => {
|
||||
return expect(fileProc.getLayers2(emptyFolder)).rejects.toThrow('Layer not found');
|
||||
return expect(fileProc.getLayers2(emptyFolder)).rejects.toThrow('Layer not found.');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user