Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test.before((t) => {
// This will capture any incoming data and put it to a file.
// Use it for verifying we are testing real data.
// Make sure to enable net connect and disable the tests you don't want
// to run with `test.skip()`!
// nock.recorder.rec({
// logging: (context) => fs.appendFile('github.log', context)
// })
nock.disableNetConnect() // Disables all real HTTP requests
db.connect(config.database)
})
require('nock').disableNetConnect();
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
const processStdoutWrite = process.stdout.write.bind(process.stdout)
process.stdout.write = (str, encoding, cb) => {
// Core library will directly call process.stdout.write for commands
function configureNock(options, config) {
var result = {};
// deny all real net connections except for localhost
nock.disableNetConnect();
nock.enableNetConnect('localhost');
function createNock(url) {
var instance = nock(url),
expectedViaHeader = options.headers['Via'] ||
'http://localhost:' + config.proxy.gateway.port,
expectedHostHeader = options.headers['Host'] || /.*/;
if (options.proxy === true) {
// verify that the request was actually proxied
// optionally support downstream proxies with non-RFC expectations on
// the Host and Via request headers
instance.matchHeader('via', expectedViaHeader);
instance.matchHeader('host', expectedHostHeader);
}
beforeEach(() => {
polyfillWindow()
nock.disableNetConnect()
instance.removeAllListeners('login')
instance.removeAllListeners('logout')
instance.removeAllListeners('session')
})
beforeAll(() => {
nock.disableNetConnect();
correctUrls.forEach(pair => {
const [url, content] = pair;
if (content) {
nock(url)
.get("")
.reply(200, content)
.persist();
} else {
nock(url)
.get("")
.reply(404, "")
.persist();
}
});
});
beforeAll(() => {
Swagger.clearCache()
if (!nock.isActive()) {
nock.activate()
}
nock.cleanAll()
nock.disableNetConnect()
const nockScope = nock('http://mock.swagger.test')
if (currentCase.remoteDocuments) {
Object.keys(currentCase.remoteDocuments).forEach((key) => {
const docContent = currentCase.remoteDocuments[key]
nockScope
.get(`/${key}`)
.reply(200, docContent, {
'Content-Type': 'application/yaml'
})
})
}
})
before(() => {
apib = fs.readFileSync(__dirname + '/fixtures/basic-swagger.yaml').toString();
nock.disableNetConnect('apiblueprint.org');
});
import { expect } from 'chai';
import nock from 'nock';
nock.disableNetConnect();
import veritoneApi from './ApiClient';
const apiBaseUrl = 'http://fake.domain';
describe('veritoneApi', function() {
describe('API methods', function() {
it('Returns the configured API functions', function() {
const api = veritoneApi(
{
token: 'token-abc',
apiToken: 'api-token-abc'
},
{
libraries: {
getLibrary: () => 'ok'
function configureNock(done) {
nock.disableNetConnect();
nock.enableNetConnect('localhost');
endpoints = [
nock('http://api.example.com')
.get('/api/hello')
.reply(200, '{ "hello": "world" }')
.get('/api/notfound')
.reply(404),
nock('http://www.example.com')
.get('/foo/12345/bar')
.reply(200, '{ "foo": "bar" }'),
nock('https://secure.example.com')
.get('/secure/api/hello')
.reply(200, '{ "hello": "world" }')
import script from './'
import nock from 'nock'
import fs from 'fs-extra'
import path from 'path'
import fm from 'front-matter'
import puppeteer from 'puppeteer'
import mockRepoData from './test-data/repo.json'
import mockReadmeData from './test-data/readme.json'
import mockReleaseData from './test-data/release.json'
nock.disableNetConnect()
nock('https://api.github.com')
.persist()
.get('/repos/boyney123/graphql.explore-tech.org')
.reply(200, mockRepoData)
.persist()
.get('/repos/boyney123/graphql.explore-tech.org/readme')
.reply(200, mockReadmeData)
.persist()
.get('/repos/boyney123/graphql.explore-tech.org/releases/latest')
.reply(200, mockReadmeData)
let exit
const scriptArgs = [
'_',