Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('push', async () => {
// Setup
const { gitdir } = await makeFixture('test-push')
await config({
gitdir,
path: 'remote.karma.url',
value: `http://${localhost}:8888/test-push-server.git`
})
const output = []
plugins.set(
'emitter',
new EventEmitter().on('push.message', output.push.bind(output))
)
// Test
const res = await push({
gitdir,
emitterPrefix: 'push.',
remote: 'karma',
ref: 'refs/heads/master'
})
expect(res).toBeTruthy()
expect(res.ok).toBeTruthy()
expect(res.ok[0]).toBe('unpack')
expect(res.ok[1]).toBe('refs/heads/master')
expect(output).toMatchSnapshot()
})
it('shallow fetch (from Github)', async () => {
const { fs, gitdir } = await makeFixture('test-fetch-cors')
await config({
gitdir,
path: 'http.corsProxy',
value: `http://${localhost}:9999`
})
const output = []
const progress = []
plugins.set(
'emitter',
new EventEmitter()
.on('fetch.message', output.push.bind(output))
.on('fetch.progress', progress.push.bind(progress))
)
// Test
await fetch({
gitdir,
emitterPrefix: 'fetch.',
depth: 1,
singleBranch: true,
remote: 'origin',
ref: 'test-branch-shallow-clone'
})
await sleep(1000) // seems to be a problem spot
expect(await fs.exists(`${gitdir}/shallow`)).toBe(true)
it('cores have separate plugins', async () => {
// Setup
const { _fs } = await makeFixture('test-cores')
plugins.set('fs', _fs)
cores.create('third').set('foo', _fs)
expect(cores.get('default').has('fs')).toBeTruthy()
expect(cores.get('default').has('foo')).toBeFalsy()
expect(cores.get('third').has('fs')).toBeFalsy()
expect(cores.get('third').get('foo')).toBeTruthy()
})
it('plugin schema violation', async () => {
it('unrecognized plugin', async () => {
// Setup
const { _fs } = await makeFixture('test-cores')
let error = null
try {
plugins.set('fz', _fs)
} catch (err) {
error = err
}
expect(error).not.toBeNull()
expect(error.code).toEqual(E.PluginUnrecognized)
})
})
it('plugin schema violation', async () => {
// Setup
const fs = {
readFile () {}
}
let error = null
try {
plugins.set('fs', fs)
} catch (err) {
error = err
}
expect(error).not.toBeNull()
expect(error.code).toEqual(E.PluginSchemaViolation)
})
it('unrecognized plugin', async () => {
it('pgp plugin signing - backwards compatiblity', async () => {
// Setup
const { pgp } = require('@isomorphic-git/pgp-plugin')
const { gitdir } = await makeFixture('test-commit')
plugins.set('pgp', pgp)
// Test
const { privateKey, publicKey } = require('./__fixtures__/pgp-keys.js')
await commit({
gitdir,
message: 'Initial commit',
author: {
name: 'Mr. Test',
email: 'mrtest@example.com',
timestamp: 1504842425,
timezoneOffset: 0
}
})
await sign({
gitdir,
privateKeys: privateKey
})
it('creates a signed tag to HEAD', async () => {
// Setup
const { pgp } = require('@isomorphic-git/pgp-plugin')
const { gitdir } = await makeFixture('test-annotatedTag')
plugins.set('pgp', pgp)
// Test
const { privateKey, publicKey } = require('./__fixtures__/pgp-keys.js')
await annotatedTag({
gitdir,
ref: 'latest',
message: 'some tag message',
tagger: {
name: 'Yu Shimura',
email: 'mail@yuhr.org'
},
signingKey: privateKey
})
const keys = await verify({
gitdir,
ref: 'latest',
publicKeys: publicKey
async function makeNodeFixture (fixture) {
const _fs = Object.assign({}, require('fs'))
const core = `core-node-${i++}`
cores.create(core).set('fs', _fs)
plugins.set('fs', _fs) // deprecated
const fs = new FileSystem(_fs)
const {
getFixturePath,
createTempDir,
copyFixtureIntoTempDir
} = require('jest-fixtures')
const testsDir = path.resolve(__dirname, '..')
const dir = (await getFixturePath(testsDir, fixture))
? await copyFixtureIntoTempDir(testsDir, fixture)
: await createTempDir()
const gitdir = (await getFixturePath(testsDir, `${fixture}.git`))
private async _start(): Promise {
console.log('[GitManager] Start');
let fsOptions = {
fs: 'IndexedDB',
options: {}
};
let configureAsync = pify(BrowserFS.configure);
await configureAsync(fsOptions);
this._fs = BrowserFS.BFSRequire('fs');
// Initialize isomorphic-git with our new file system
gitPlugins.set('fs', this._fs);
this._pfs = pify(this._fs);
let dir = 'default';
}
import fs from "fs"
import * as git from "isomorphic-git"
import path from "path"
import rimraf from "rimraf"
import uuid from "uuid"
import { plugins } from "isomorphic-git"
plugins.set("fs", fs)
const repos: string[] = []
afterAll(() => {
repos.map(repo => {
rimraf.sync(repo)
})
})
export async function createTempGitProject() {
const tempRoot = "/tmp/__tempRoot__" + uuid()
repos.push(tempRoot)
await fs.promises.mkdir(tempRoot)
await git.init({ dir: tempRoot })