Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('mergeFiles', function (t) {
t.plan(isWindows ? 1 : 2);
var releasefile = temp.openSync();
fs.writeFileSync(releasefile.path, 'A');
var zipFile = temp.openSync();
fs.writeFileSync(zipFile.path, 'B');
utils.mergeFiles(releasefile.path, zipFile.path, '0755').then(function() {
var contents = fs.readFileSync(releasefile.path);
var stats = fs.lstatSync(releasefile.path);
t.equal(contents.toString(), 'AB', 'merge two files');
if(!isWindows) {
t.equal(stats.mode.toString(8), '100755', 'fix the permission'); // DOES NOT WORK ON WINDOWS
}
});
});
function checkCode(code) {
var instCode = esnstrument.instrumentCodeDeprecated(code, {wrapProgram: false, dirIIDFile: temp.dir}).code;
// console.log(instCode);
var ast = acorn.parse(instCode);
// NOTE: this is not a robust way to do a deep copy of ASTs,
// just good enough for unit tests
// console.log("init:\n" + JSON.stringify(ast,undefined,2));
var astCopy = JSON.parse(JSON.stringify(ast));
var table = astUtil.serialize(ast);
// assert.deepEqual(ast,astCopy); would fail here
// console.log("serialized:\n" + JSON.stringify(ast,undefined,2));
astUtil.deserialize(table);
// console.log("deserialized:\n" + JSON.stringify(ast,undefined,2));
assert.deepEqual(ast,astCopy);
}
export async function cloneRepository(repoName = 'three-files') {
if (!cachedClonedRepos[repoName]) {
const cachedPath = temp.mkdirSync('git-fixture-cache-');
const git = new GitShellOutStrategy(cachedPath);
await git.clone(path.join(__dirname, 'fixtures', `repo-${repoName}`, 'dot-git'), {noLocal: true});
await git.exec(['config', '--local', 'core.autocrlf', 'false']);
await git.exec(['config', '--local', 'commit.gpgsign', 'false']);
await git.exec(['config', '--local', 'user.email', FAKE_USER.email]);
await git.exec(['config', '--local', 'user.name', FAKE_USER.name]);
await git.exec(['config', '--local', 'push.default', 'simple']);
await git.exec(['checkout', '--', '.']); // discard \r in working directory
cachedClonedRepos[repoName] = cachedPath;
}
return copyCachedRepo(repoName);
}
exports.configurate = function () {
if (!lconfig) {
// override from the system temporary directory because of the locker's insane insistence on relative paths.
temp.dir = '.';
process.env.NODE_PATH = path.join(__dirname, '..', '..', 'Common', 'node');
process.env.LOCKER_ROOT = path.join(__dirname, '..', '..');
process.env.LOCKER_CONFIG = path.join(__dirname, '..', 'resources');
process.env.LOCKER_ME = temp.path({prefix : 'Me.',
suffix : '.test'});
lconfig = require(path.join(__dirname, '..', '..', 'Common', 'node', 'lconfig.js'));
lconfig.load(path.join(process.env.LOCKER_CONFIG, 'config.json'));
}
return lconfig;
};
it('relativizes against both the linked path and the real path', () => {
// Creating symbol link on Windows requires administrator permission so
// we just skip this test.
if (process.platform === 'win32') { return }
const repoDirectory = fs.realpathSync(temp.mkdirSync('node-git-repo-'))
const linkDirectory = path.join(fs.realpathSync(temp.mkdirSync('node-git-repo-')), 'link')
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures/master.git'), path.join(repoDirectory, '.git'))
fs.symlinkSync(repoDirectory, linkDirectory)
repo = git.open(linkDirectory)
expect(repo.relativize(path.join(repoDirectory, 'test1'))).toBe('test1')
expect(repo.relativize(path.join(linkDirectory, 'test2'))).toBe('test2')
expect(repo.relativize(path.join(linkDirectory, 'test2/test3'))).toBe('test2/test3')
expect(repo.relativize('test2/test3')).toBe('test2/test3')
})
})
res.sendSafely(_.bind(function(cb) {
var urlPath = req.params[0].split('/');
if (urlPath.length > 1 && urlPath[0] == imagesDirName) {
var imageFileName = urlPath[1];
// var imageSize = urlPath[2];
// var imagePath = path.join(blog.contentPaths[0].path, imagesDirName,
// imageFileName);
var imageSize = null;//urlPath[2];
var imagePath = path.join(blog.contentPaths[0].path, imagesDirName,
urlPath.slice(1).join('/'));
if (!imageSize) {
cb(0, {path: imagePath});
} else {
var temp = require('temp');
var tempPath = temp.path({suffix: path.extname(imagePath)});
var options = {
srcPath: imagePath,
dstPath: tempPath
};
var m = /^\s*(\d*)x(\d*)\s*$/.exec(imageSize);
if (m) {
if (m[1]) {
options.width = parseInt(m[1]);
}
if (m[2]) {
options.height = parseInt(m[2]);
}
}
if (options.width && options.height) {
function copyConfig(callback) {
temp.open({}, function(err, tempfile) {
if (err) throw err;
var config = {
// Our keys for signing certificates
gnomn_public_key: JSON.parse(fs.readFileSync(path.join(__dirname, '../../sekret/key.publickey'))),
gnomn_private_key: JSON.parse(fs.readFileSync(path.join(__dirname, '../../sekret/key.secretkey'))),
// Yubico client api keys
yubico_client_id: getenv('YUBICO_CLIENT_ID'),
yubico_secret_key: getenv('YUBICO_SECRET_KEY')
};
fs.writeFileSync(tempfile.path, JSON.stringify(config), 'utf8');
var dest = 'app@'+getenv('AWS_IP_ADDRESS')+':'+CONFIG_FILE
console.log("Copying config");
beforeEach(async () => {
jasmine.unspy(global, 'setTimeout');
atom.project.setPaths([
temp.mkdirSync('other-dir-'),
temp.mkdirSync('atom-symbols-view-'),
]);
directory = atom.project.getDirectories()[1];
fs.copySync(path.join(__dirname, 'fixtures', 'js'), atom.project.getPaths()[1]);
activationPromise = atom.packages.activatePackage('symbols-view-plus');
jasmine.attachToDOM(getWorkspaceView());
// NOTE: to be compatible with atom/symbols-view
atom.config.set(
'symbols-view-plus.plusConfigurations.symbolsViewTheme',
'Modal Panel (like atom/symbols-view)'
);
});
beforeEach(() => {
temp.track()
env = Object.assign({}, process.env)
if (isTruthy(env.GOROOT)) {
delete env.GOROOT
}
environmentFn = () => {
return env
}
readyFn = () => { return true }
platform = process.platform
if (process.arch === 'arm') {
arch = 'arm'
} else if (process.arch === 'ia32') {
// Ugh, Atom is 32-bit on Windows... for now.
if (platform === 'win32') {
arch = 'amd64'
} else {
async function writeHtmlToTempFile(html?: string): Promise {
if (!html) {
return;
}
try {
const tempFile = temp.path({ prefix: 'sme-result-', suffix: '.html' });
fs.writeFileSync(tempFile, html);
const childProcess = await open(tempFile);
if (childProcess.stderr) {
// Catch error output from child process
childProcess.stderr.once('data', (error: Buffer) => {
logError({ code: 'CannotOpenTempFile', tempFile, error });
});
}
} catch (error) {
throw new AppError({ code: 'CannotCreateTempFile' }, error);
}
}