Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('preparePull (Github response)', async () => {
// Setup
const { nockDone } = await nock.back(
'GitRemoteHTTP - preparePull (Github response).json'
)
// Test
const remote = await GitRemoteHTTP.discover({
core: 'default',
service: 'git-upload-pack',
url: 'https://github.com/isomorphic-git/isomorphic-git',
headers: {}
})
expect(remote).toBeTruthy()
expect(remote.symrefs.size > 0)
expect(remote.symrefs.get('HEAD')).toBe('refs/heads/master')
// Teardown
nockDone()
})
it('preparePull (mock response)', async () => {
// Setup
const { nockDone } = await nock.back(
'GitRemoteHTTP - preparePull (mock response).json'
)
// Test
const remote = await GitRemoteHTTP.discover({
core: 'default',
service: 'git-upload-pack',
url: 'http://example.dev/test-GitRemoteHTTP',
headers: {}
})
expect(remote).toBeTruthy()
// Teardown
nockDone()
})
it('basic pull', async () => {
// Setup
const { nockDone } = await nock.back('pull - basic pull.json')
const { dir, gitdir } = await makeFixture('test-pull-client')
// Test
const desiredOid = '97c024f73eaab2781bf3691597bc7c833cb0e22f'
await pull({
dir,
gitdir,
ref: 'master',
fastForwardOnly: true
})
const oid = await resolveRef({
gitdir,
ref: 'master'
})
expect(oid).toEqual(desiredOid)
// Teardown
nockDone()
export async function record (p: string, opts?: INockOptions) {
const options: any = {} // tslint:disable-line no-any
if (opts != null && opts.ignoreBody === true) {
options.before = (scope) => {
scope.filteringRequestBody = () => '*'
}
}
const { nockDone } = await nock.back(p, options)
return { done: nockDone }
}
request.get('http://example.test', (err: any, res: any, body: string) => {
nockDone()
// usage of the created fixture
nock.back('fixture.json', (nockDone: () => void) => {
nockDone() // never gets here
})
})
})
beforeEach((done) => {
nock.back(filename, cb => {
nockDone = cb;
// Nock fucks everything up unless we keep re-enabling connections to
// Express.
nock.enableNetConnect('127.0.0.1');
done();
});
});
it('should make use of options.from and options.size', () => {
let nockDone;
nockBack('search-react-with-from-and-limit.json', (_nockDone) => { nockDone = _nockDone; });
return queries.search('react', localEsClient, { from: 1, size: 1 })
.then((res) => {
expect(res.total).to.be.greaterThan(1);
expect(res.results).to.have.length(1);
expect(res.results[0].package.name).to.not.equal('react');
nockDone();
});
});
it('should return the desired results', () => {
let nockDone;
nockBack('search-similar.json', (_nockDone) => { nockDone = _nockDone; });
return queries.search.similar('chaik', localEsClient)
.then((similar) => {
expect(similar).to.have.length(10);
expect(similar[0]).to.contain.all.keys('package', 'score', 'searchScore');
expect(similar[0].package.name).to.equal('chalk');
nockDone();
});
});
it('should return the desired results of a complex query', () => {
let nockDone;
nockBack('search-complex-query-spawn.json', (_nockDone) => { nockDone = _nockDone; });
return queries.search('maintainer:satazor keywords:spawn,-foo is:deprecated not:insecure boost-exact:no spawn', localEsClient)
.then((res) => {
expect(res.total).to.equal(1);
expect(res.results).to.have.length(1);
expect(res.results[0].package.name).to.equal('cross-spawn-async');
nockDone();
});
});
it('should allow to search all packages of an author', () => {
let nockDone;
nockBack('search-author-sindresorhus.json', (_nockDone) => { nockDone = _nockDone; });
return queries.search('author:sindresorhus', localEsClient)
.then((res) => {
expect(res.total).to.equal(943);
expect(res.results).to.have.length(25);
res.results.forEach((result) => expect(result.package.author.username).to.equal('sindresorhus'));
nockDone();
});
});