Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(function () {
const currentTest = this.currentTest;
try {
// we want snapshot tests to use the same random data between runs
const faker = require("faker");
let seed = 0;
for (let i = 0; i < currentTest.fullTitle().length; ++i)
seed += currentTest.fullTitle().charCodeAt(i);
faker.seed(seed);
} catch (e) {
// may throw if package doesn't use faker - ignore
}
// set up snapshot name
const sourceFilePath = currentTest.file.replace("lib\\test", "src\\test").replace(/\.(jsx?|tsx?)$/, "");
const snapPath = sourceFilePath + ".snap";
chaiJestSnapshot.setFilename(snapPath);
chaiJestSnapshot.setTestName(currentTest.fullTitle());
chai.spy.restore();
});
// Extract the options from the command line
let argv = yargs
.boolean(`debugPaintRects`)
.default(`debugPaintRects`, false)
.argv;
// Register the segfault handler, just in case
registerHandler();
// Use a static seed so that everybody will get the same output
faker.seed(42);
// Hook the output depending on the command line options
let stdout = undefined;
if (argv.output === undefined) {
stdout = process.stdout;
} else if (argv.output === `encoded`) {
stdout = Object.assign(Object.create(process.stdout), { write: str => console.log(JSON.stringify(str)) });
} else if (argv.output === false) {
stdout = Object.assign(Object.create(process.stdout), { write: str => undefined });
} else {
throw new Error(`Failed to execute: Invalid output '${argv.output}'.`);
}
// Setup the screen
UserModel.belongsToMany(UserModel, { through: 'Friends', as: 'friends' });
// messages are sent from users
MessageModel.belongsTo(UserModel);
// messages are sent to groups
MessageModel.belongsTo(GroupModel);
// groups have multiple users
GroupModel.belongsToMany(UserModel, { through: 'GroupUser' });
// create fake starter data
const GROUPS = 4;
const USERS_PER_GROUP = 5;
const MESSAGES_PER_USER = 5;
faker.seed(123); // get consistent data every time we reload app
// you don't need to stare at this code too hard
// just trust that it fakes a bunch of groups, users, and messages
db.sync({ force: true }).then(() => _.times(GROUPS, () => GroupModel.create({
name: faker.lorem.words(3),
}).then(group => _.times(USERS_PER_GROUP, () => {
const password = faker.internet.password();
return bcrypt.hash(password, 10).then(hash => group.createUser({
email: faker.internet.email(),
username: faker.internet.userName(),
password: hash,
}).then((user) => {
console.log(
'{email, username, password}',
`{${user.email}, ${user.username}, ${password}}`
);
/* eslint-env node */
import webpackMiddleware from 'webpack-dev-middleware'
import express from 'express'
import bodyParser from 'body-parser'
import { graphqlExpress } from 'apollo-server-express'
import gql from 'graphql-tag'
import { makeExecutableSchema } from 'graphql-tools'
import webpackConfig from '../webpack.config'
import webpack from 'webpack'
import morgan from 'morgan'
import path from 'path'
import times from 'lodash.times'
import faker from 'faker'
faker.seed(123)
const graphiQlIndexPath = path.join(__dirname, `index.html`)
const mockAuthors = times(50, () => ({
id: faker.random.uuid(),
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
}))
const mockPosts = times(100, () => ({
id: faker.random.uuid(),
title: faker.lorem.words(),
votes: faker.random.number({ min: 0, max: 10 }),
authorId:
mockAuthors[faker.random.number({ min: 0, max: mockAuthors.length - 1 })]
.id,
export default async function makeQuestionDummy(number = 100) {
const {INIT_SEED, GUEST_NUM} = config;
faker.seed(INIT_SEED);
const bulkQuestion = [];
for (let i = 0; i < number; ++i) {
const content = faker.lorem.sentence();
const createdAt = faker.date.past(1);
const updatedAt = createdAt;
const state = "active";
const GuestId = faker.random.number({min: 1, max: GUEST_NUM});
// eslint-disable-next-line no-await-in-loop
const res = await getGuestById(GuestId);
const EventId = res.dataValues.EventId;
const QuestionId = null;
const isStared = false;
const likeCount = 0;
bulkQuestion.push({
const seed = (value?: number) => {
if (value) {
faker.seed(value);
}
return enumFactoryObject;
};
import faker from "faker";
import moment from "moment";
import config from "./initialConfig";
const {INIT_SEED, EVENT_NUM} = config;
faker.seed(INIT_SEED);
export default function makeEventDummy(number = EVENT_NUM) {
const bulkEvent = [];
const filter = {};
for (let i = 0; i < number; ++i) {
let alphaNum = faker.random.alphaNumeric(4);
while (filter[alphaNum]) {
alphaNum = faker.random.alphaNumeric(4);
}
const eventCode = alphaNum;
filter[eventCode] = 1;
const moderationOption = faker.random.boolean();
const replyOption = faker.random.boolean();
const faker = require('faker');
const jsonfile = require('jsonfile');
const numUsers = 10;
const tweetsPerUser = 5;
const followersPerUser = 2;
const udata = [];
const tdata = [];
const handleNames = [];
faker.seed(1000);
for (let i = 0; i < numUsers; i++) {
const handle = faker.internet.userName();
handleNames.push(handle);
}
for (let i = 0; i < handleNames.length; i++) {
const following = [];
//create user info
for (let k = 0; k < followersPerUser; k++) {
following.push(handleNames[Math.floor(Math.random() * handleNames.length)]);
}
const followers_count = faker.random.number({
min: 1,
import faker from "faker";
import config from "./initialConfig";
const {INIT_SEED, EVENT_NUM, GUEST_NUM} = config;
faker.seed(INIT_SEED);
export default function makeGuestDummy(number = GUEST_NUM) {
const bulkGuest = [];
for (let i = 0; i < number; ++i) {
const name = faker.name.firstName();
const guestSid = faker.random.uuid();
const createdAt = faker.date.past(1);
const updatedAt = createdAt;
const EventId = faker.random.number({min: 1, max: EVENT_NUM});
const isAnonymous = false;
bulkGuest.push({
name,
createdAt,
updatedAt,
import faker from "faker";
import config from "./initialConfig";
const {INIT_SEED, EVENT_NUM} = config;
faker.seed(INIT_SEED);
export default function makeHashTagDummy(number = 100) {
const bulkHashTag = [];
for (let i = 0; i < number; ++i) {
const name = faker.hacker.ingverb();
const createdAt = faker.date.past(1);
const updatedAt = createdAt;
const EventId = faker.random.number({min: 1, max: EVENT_NUM});
bulkHashTag.push({name, createdAt, updatedAt, EventId});
}
return bulkHashTag;
}