Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mock({
[DUMMY_CONFIG_DIRECTORY_PATH]: {
...templates2files(mock_templates),
// add directory without template.json
"non-template": {
"this-is-not-template.json": JSON.stringify({
task: {
submit: "main.cpp",
program: ["main.cpp"]
}
})
}
}
});
const result = await template.getTemplates();
mock.restore();
// there's no template "non-template"
expect(result).toMatchSnapshot();
});
test("files to be ignored", async () => {
test('should return false if build folder exists', async () => {
mock({ 'dist': { 'index.html': 'Fake content' }});
const exists = await checkIfBuildFolderExists();
expect(exists).toBe(false);
mock.restore();
});
test('should be false if directories do exist', async () => {
mock(fsConfig, { createCwd: false, createTmp: false });
const [check] = await checkIfLayoutAndPageDirectoriesExist();
expect(check).toBe(false);
mock.restore();
});
afterEach(() => {
mockFs.restore();
});
export function restoreFs() {
mockFs.restore();
}
exports.restoreMock = function restoreMock(){
mockDir.restore();
}
it("should return true when it is able to save a config file", async () => {
sinon.stub(os, 'homedir').returns('/nonsense');
mock({ '/nonsense': {}});
let config = new IqServerConfig("username", "password", "http://localhost:8070");
let configPersist = new ConfigPersist("username", "password", "http://localhost:8070")
expect(config.saveFile(configPersist)).to.equal(true);
let conf = config.getConfigFromFile('/nonsense/.iqserver/.iq-server-config');
expect(conf.getUsername()).to.equal('username');
expect(conf.getToken()).to.equal('password');
expect(conf.getHost()).to.equal('http://localhost:8070');
mock.restore();
sinon.restore();
});
});
it("should return true when it is able to save a config file", async () => {
sinon.stub(os, 'homedir').returns('/nonsense');
mock({ '/nonsense': {}});
let config = new OssIndexServerConfig("username", "password");
let configPersist = new ConfigPersist("username", "password")
expect(config.saveFile(configPersist)).to.equal(true);
let conf = config.getConfigFromFile('/nonsense/.ossindex/.oss-index-config');
expect(conf.getUsername()).to.equal('username');
expect(conf.getToken()).to.equal('password');
mock.restore();
sinon.restore();
});
});
it("Get files", () => {
mock({
dir1: {
d1: {},
"f1.md": "file",
f2: "file"
},
dir2: {}
});
expect(
arrayAreEqual(getFiles("dir1"), ["f1"])
).toBeTruthy();
expect(
arrayAreEqual(getFiles("dir2"), [])
).toBeTruthy();
mock.restore();
});
afterEach(() => {
mockFs.restore();
})
});