How to use testResolver method in qawolf

Best JavaScript code snippet using qawolf

scoperesolver_test.js

Source:scoperesolver_test.js Github

copy

Full Screen

...67 expected.sort(scopeCompare);68 assume(resolver(scopes)).eql(expected);69 });70 };71 testResolver('scopes pass through', {72 roles: [],73 scopes: ['a', 'b', 'c*'],74 expected: ['a', 'b', 'c*'],75 });76 testResolver('passed through scopes are normalized', {77 roles: [],78 scopes: ['a*', 'ab', 'ac*', 'a'],79 expected: ['a*'],80 });81 testResolver('assume:a* matches, a, aa, ab, a*', {82 roles: [83 { role_id: 'a', scopes: ['A'] },84 { role_id: 'aa', scopes: ['AA'] },85 { role_id: 'ab', scopes: ['AB'] },86 { role_id: 'a*', scopes: ['ASTAR'] },87 ],88 scopes: ['assume:a*'],89 expected: ['assume:a*', 'A', 'AA', 'AB', 'ASTAR'],90 });91 testResolver('ab* matches ab, abc', {92 roles: [93 { role_id: 'a', scopes: ['A'] },94 { role_id: 'ab', scopes: ['AB'] },95 { role_id: 'abc', scopes: ['ABC'] },96 ],97 scopes: ['assume:ab*'],98 expected: ['assume:ab*', 'AB', 'ABC'],99 });100 testResolver('a gets a*', {101 roles: [102 { role_id: 'a*', scopes: ['ASTAR'] },103 { role_id: 'ab*', scopes: ['ABSTAR'] },104 ],105 scopes: ['assume:a'],106 expected: ['assume:a', 'ASTAR'],107 });108 testResolver('max sets (with long scopes)', {109 roles: [110 { role_id: 'ab*', scopes: ['ABSTAR'] },111 { role_id: 'aaaaaaaaaaaaa', scopes: ['long'] },112 { role_id: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', scopes: ['longer'] },113 { role_id: 'ababaabdssafsdcsdcsacwscwcscsesdsdfdsfdsfsdfsfdsdfsdfsdfsafewfsewfwsd', scopes: ['longest'] },114 ],115 scopes: ['assume:ab*'],116 expected: ['assume:ab*', 'ABSTAR', 'longest'],117 });118 testResolver('ab gets ab*, a*', {119 roles: [120 { role_id: 'ab*', scopes: ['ABSTAR'] },121 { role_id: 'a*', scopes: ['ASTAR'] },122 ],123 scopes: ['assume:ab'],124 expected: ['assume:ab', 'ABSTAR', 'ASTAR'],125 });126 testResolver('a gets * and a', {127 roles: [128 { role_id: '*', scopes: ['STAR'] },129 { role_id: 'a*', scopes: ['ASTAR'] },130 ],131 scopes: ['assume:a'],132 expected: ['assume:a', 'STAR', 'ASTAR'],133 });134 testResolver('a*, b*, c*', {135 roles: [136 { role_id: 'a*', scopes: ['ASTAR'] },137 { role_id: 'ab*', scopes: ['ABSTAR'] },138 { role_id: 'ac*', scopes: ['ACSTAR'] },139 { role_id: 'd', scopes: ['D'] },140 ],141 scopes: ['assume:ab'],142 expected: ['assume:ab', 'ASTAR', 'ABSTAR'],143 });144 testResolver('ab* matches a*', {145 roles: [146 { role_id: 'a*', scopes: ['ASTAR'] },147 { role_id: 'aabc', scopes: ['AABC'] },148 ],149 scopes: ['assume:aa*'],150 expected: ['assume:aa*', 'ASTAR', 'AABC'],151 });152 testResolver('* get all', {153 roles: [154 { role_id: 'a', scopes: ['A'] },155 { role_id: 'b', scopes: ['B'] },156 { role_id: 'c', scopes: ['C'] },157 ],158 scopes: ['*'],159 expected: ['*'],160 });161 testResolver('a* get all', {162 roles: [163 { role_id: 'a', scopes: ['A'] },164 { role_id: 'b', scopes: ['B'] },165 { role_id: 'c', scopes: ['C'] },166 ],167 scopes: ['a*'],168 expected: ['a*', 'A', 'B', 'C'],169 });170 testResolver('assume* get all', {171 roles: [172 { role_id: 'a', scopes: ['A'] },173 { role_id: 'b', scopes: ['B'] },174 { role_id: 'c', scopes: ['C'] },175 ],176 scopes: ['assume*'],177 expected: ['assume*', 'A', 'B', 'C'],178 });179 testResolver('assume:* get all', {180 roles: [181 { role_id: 'a', scopes: ['A'] },182 { role_id: 'b', scopes: ['B'] },183 { role_id: 'c', scopes: ['C'] },184 ],185 scopes: ['assume:*'],186 expected: ['assume:*', 'A', 'B', 'C'],187 });188 testResolver('assum* get all', {189 roles: [190 { role_id: 'a', scopes: ['A'] },191 { role_id: 'b', scopes: ['B'] },192 { role_id: 'c', scopes: ['C'] },193 ],194 scopes: ['assum*'],195 expected: ['assum*', 'A', 'B', 'C'],196 });197 testResolver('assume:a works', {198 roles: [199 { role_id: 'a', scopes: ['A'] },200 { role_id: 'b', scopes: ['B'] },201 { role_id: 'c', scopes: ['C'] },202 ],203 scopes: ['assume:a'],204 expected: ['assume:a', 'A'],205 });206 testResolver('exact match ab', {207 roles: [208 { role_id: 'a', scopes: ['A'] },209 { role_id: 'ab', scopes: ['AB'] },210 { role_id: 'abc', scopes: ['ABC'] },211 ],212 scopes: ['assume:ab'],213 expected: ['assume:ab', 'AB'],214 });215 testResolver('ab* matches ab, abc', {216 roles: [217 { role_id: 'a', scopes: ['A'] },218 { role_id: 'ab', scopes: ['AB'] },219 { role_id: 'abc', scopes: ['ABC'] },220 ],221 scopes: ['assume:ab*'],222 expected: ['assume:ab*', 'AB', 'ABC'],223 });224 testResolver('ab* matches a*', {225 roles: [226 { role_id: 'a*', scopes: ['ASTAR'] },227 { role_id: 'ab', scopes: ['AB'] },228 { role_id: 'abc', scopes: ['ABC'] },229 ],230 scopes: ['assume:ab*'],231 expected: ['assume:ab*', 'ASTAR', 'AB', 'ABC'],232 });233 testResolver('ab match ab,a*', {234 roles: [235 { role_id: 'a*', scopes: ['ASTAR'] },236 { role_id: 'ab', scopes: ['AB'] },237 { role_id: 'abc', scopes: ['ABC'] },238 ],239 scopes: ['assume:ab'],240 expected: ['assume:ab', 'ASTAR', 'AB'],241 });242 testResolver('a*b* matches a*b, a*bc', {243 roles: [244 { role_id: 'a', scopes: ['A'] },245 { role_id: 'a*b', scopes: ['ASTARB'] },246 { role_id: 'a*bc', scopes: ['ASTARBC'] },247 { role_id: 'ab', scopes: ['AB'] },248 { role_id: 'abc', scopes: ['ABC'] },249 { role_id: 'b*', scopes: ['BSTAR'] },250 { role_id: 'c*', scopes: ['CSTAR'] },251 { role_id: 'ab*', scopes: ['ABSTAR'] },252 ],253 scopes: ['assume:a*b*'],254 expected: ['assume:a*b*', 'ASTARB', 'ASTARBC'],255 });256 testResolver('a*b matches a*, a*b', {257 roles: [258 { role_id: 'a*', scopes: ['ASTAR'] },259 { role_id: 'a*b', scopes: ['ASTARB'] },260 { role_id: 'a*bc', scopes: ['ASTARBC'] },261 { role_id: 'ab', scopes: ['AB'] },262 { role_id: 'abc', scopes: ['ABC'] },263 { role_id: 'b*', scopes: ['BSTAR'] },264 { role_id: 'c*', scopes: ['CSTAR'] },265 { role_id: 'ab*', scopes: ['ABSTAR'] },266 ],267 scopes: ['assume:a*b'],268 expected: ['assume:a*b', 'ASTARB', 'ASTAR'],269 });270 testResolver('a*b* matches a*b, a*bc', {271 roles: [272 { role_id: 'a*', scopes: ['ASTAR'] },273 { role_id: 'a*b', scopes: ['ASTARB'] },274 { role_id: 'a*bc', scopes: ['ASTARBC'] },275 { role_id: 'ab', scopes: ['AB'] },276 { role_id: 'abc', scopes: ['ABC'] },277 { role_id: 'b*', scopes: ['BSTAR'] },278 { role_id: 'c*', scopes: ['CSTAR'] },279 { role_id: 'ab*', scopes: ['ABSTAR'] },280 ],281 scopes: ['assume:a*b*'],282 expected: ['assume:a*b*', 'ASTARB', 'ASTARBC', 'ASTAR'],283 });284 testResolver('basic parameterized role', {285 roles: [286 { role_id: 'a*', scopes: ['A<..>'] },287 ],288 scopes: ['assume:abc'],289 expected: ['assume:abc', 'Abc'],290 });291 testResolver('basic parameterized role, matched with *', {292 roles: [293 { role_id: 'a*', scopes: ['A<..>'] },294 ],295 scopes: ['assume:abc*'],296 expected: ['assume:abc*', 'Abc*'],297 });298 testResolver('parameterized role with suffix', {299 roles: [300 { role_id: 'a*', scopes: ['A<..>X'] },301 ],302 scopes: ['assume:abc'],303 expected: ['assume:abc', 'AbcX'],304 });305 testResolver('parameterized role with suffix, matched with *', {306 roles: [307 { role_id: 'a*', scopes: ['A<..>X'] },308 ],309 scopes: ['assume:abc*'],310 expected: ['assume:abc*', 'Abc*'],311 });312 testResolver('parameterized role with suffix, matched with a shorter *', {313 roles: [314 { role_id: 'abc*', scopes: ['ABC<..>DEF'] },315 ],316 scopes: ['assume:a*'],317 expected: ['assume:a*', 'ABC*'],318 });319 });320 suite('performance', function() {321 const shouldMeasure = process.env.MEASURE_PERFORMANCE;322 let time;323 if (shouldMeasure) {324 // this could take a while..325 this.slow(3600000);326 this.timeout(0);327 const MIN_ITERATIONS = 5; // during warmup only328 const PREHEAT_TIME = 500 * 1000000; // ns329 const TIMEING_TIME = 2 * 1000000000; // ns330 time = (step, fn) => {331 let result;332 let mean;333 let count = 0;334 // initial runs to skip (allows JIT warmup)335 // we also use this to estimate how many iterations we need to run336 // inorder to do timing for TIMEING_TIME time.337 const preheat = hrtime.bigint();338 while (true) {339 for (let i = 0; i < MIN_ITERATIONS; i++) {340 result = fn();341 }342 count += 1;343 const end = hrtime.bigint();344 if (end - preheat > PREHEAT_TIME) {345 mean = Number(end - preheat) / (MIN_ITERATIONS * count);346 break;347 }348 }349 // Estimate iterations to measure and run them350 let iterations = Math.ceil(TIMEING_TIME / mean);351 const start = hrtime.bigint();352 for (let i = 0; i < iterations; i++) {353 result = fn();354 }355 const end = hrtime.bigint();356 mean = Number(end - start) / iterations;357 let unit = 'ns';358 if (mean > 1000) {359 mean /= 1000;360 unit = 'μs';361 }362 if (mean > 1000) {363 mean /= 1000;364 unit = 'ms';365 }366 console.log(`${step}: ${mean.toFixed(2)} ${unit}`);367 return result;368 };369 } else {370 time = (step, fn) => fn();371 }372 const testResolver = (title, { roles, scopes, expected }) => {373 test(title, function() {374 let resolver = time('setup', () => scopeResolver.buildResolver(roles));375 time('execute', () => resolver(scopes));376 if (expected) {377 expected.sort(scopeCompare);378 assert.deepEqual(expected, resolver(scopes));379 }380 });381 };382 // test a chain of N roles, each one leading to the next383 // ch-1 -> ... -> assume:ch-N -> special-scope384 const testChain = N => {385 testResolver(`chain of ${N} roles`, {386 roles: _.range(N).map(i => ({ role_id: `ch-${i}`, scopes: [`assume:ch-${i + 1}`] })).concat([387 { role_id: `ch-${N}`, scopes: ['special-scope'] },388 ]),389 scopes: ['assume:ch-0'],390 expected: _.range(N).map(i => `assume:ch-${i}`).concat([391 `assume:ch-${N}`,392 'special-scope',393 ]),394 });395 };396 testChain(500);397 if (shouldMeasure) {398 testChain(750);399 testChain(1000);400 testChain(1250);401 testChain(1500);402 }403 // test a tree of roles H roles deep, with each row growing by W404 // t ---> t-1 ---> t-1-1 ---> ... t-1-1-1-1-1405 // t-2 .. t-1-2 \---H---/406 // .. ..407 // t-W ..408 const testTree = (W, H) => {409 const roles = [];410 const recur = (prefix, h) => {411 const role_ids = _.range(W).map(w => `${prefix}-${w}`);412 if (h !== H) {413 role_ids.forEach(role_id => recur(role_id, h + 1));414 }415 roles.push({416 role_id: prefix,417 scopes: role_ids.map(role_id => `assume:${role_id}`),418 });419 };420 recur('t', 0);421 testResolver(`tree of ${W}x${H} roles`, {422 roles,423 scopes: ['assume:t'],424 expected: _.flatten(roles.map(r => r.scopes)).concat(['assume:t']),425 });426 };427 testTree(2, 3);428 if (shouldMeasure) {429 testTree(1, 4);430 testTree(2, 4);431 testTree(2, 5);432 testTree(2, 6);433 testTree(3, 3);434 testTree(3, 4);435 testTree(3, 5);436 testTree(4, 4);437 }438 // Test with a snapshot of real roles, captured with439 // `curl https://auth.taskcluster.net/v1/roles > test/roles.json`440 const realRoles = require('./roles');441 const testRealRoles = (scopes, expected) => {442 testResolver(`real roles with scopes ${scopes.join(', ')}`, {443 roles: realRoles,444 scopes,445 expected,446 });447 };448 testRealRoles(['assume:*'], [449 'assume:*',450 'auth:*',451 'aws-provisioner:*',452 'docker-worker:*',453 'ec2-manager:*',454 'generic-worker:*',455 'github:*',456 'hooks:*',...

Full Screen

Full Screen

resolver-test.ts

Source:resolver-test.ts Github

copy

Full Screen

...39 expect(resolvedValue.__typename).toBe(TYPENAME);40 });41 test('must include properties that the original function returns', () => {42 const resolverInput = { message: 'foo' };43 const preResolverOutput = testResolver(resolverInput);44 const builtResolver = createResolver(TYPENAME, testResolver);45 const resolvedValue = builtResolver(resolverInput);46 // TypeScript Guard47 if (!resolvedValue) {48 throw new Error('resolvedValue is empty in this test');49 }50 expect(resolvedValue).toEqual({51 __typename: TYPENAME,52 ...preResolverOutput,53 });54 });55});56describe(createConnectionResolver, () => {57 beforeEach(() => jest.clearAllMocks());58 // We are testing reference equality. If in the future more than node must be59 // added, then one cursorRef must be created per node.60 const cursorRef = () => 'foo';61 const connectionAttributes = {62 edges: jest.fn(async function edges() {63 return [64 {65 node() {66 return { message: 'foo' };67 },68 cursor: cursorRef,69 },70 ];71 }),72 pageInfo: {73 async count() {74 return 1;75 },76 async hasPreviousPage() {77 return false;78 },79 async hasNextPage() {80 return false;81 },82 },83 };84 test('must include correct typename after calling resolver', () => {85 const builtConnectionResolver = createConnectionResolver(TYPENAME, testResolver);86 // Resolve the connection87 const resolvedConnection = builtConnectionResolver(connectionAttributes);88 expect(resolvedConnection.__typename).toBe(`${TYPENAME}Connection`);89 });90 test('must directly wire pageInfo from the attributes property', () => {91 const builtConnectionResolver = createConnectionResolver(TYPENAME, testResolver);92 // Resolve the connection93 const resolvedConnection = builtConnectionResolver(connectionAttributes);94 expect(resolvedConnection.pageInfo).toBe(connectionAttributes.pageInfo);95 });96 test(97 'must not call edges() on the attributes object if the result ' +98 'edges() property has not been called',99 () => {100 const builtConnectionResolver = createConnectionResolver(TYPENAME, testResolver);101 // Resolve the connection102 builtConnectionResolver(connectionAttributes);103 // Nothing should have happened104 expect(connectionAttributes.edges).not.toHaveBeenCalled();105 },106 );107 test(108 'must call edges() on the attributes object with the ' +109 'correct arguments when the result edges() property is called called',110 async () => {111 expect.assertions(1);112 const builtConnectionResolver = createConnectionResolver(TYPENAME, testResolver);113 const resolverContext = { foo: 'bar' };114 // Resolve the connection115 const resolvedConnection = builtConnectionResolver(connectionAttributes, resolverContext);116 await resolvedConnection.edges();117 // Nothing should have happened118 expect(connectionAttributes.edges).toHaveBeenCalledWith(null, resolverContext);119 },120 );121 test(122 'must not call resolver function if edges().node() function ' + 'has not been invoked',123 async () => {124 expect.assertions(1);125 const builtConnectionResolver = createConnectionResolver(TYPENAME, testResolver);126 // Resolve the connection127 const resolvedConnection = builtConnectionResolver(connectionAttributes);128 await resolvedConnection.edges();129 expect(testResolver).not.toHaveBeenCalled();130 },131 );132 test(133 'must call resolver function with correct arguments ' + 'if edges().node() function is invoked',134 async () => {135 const builtConnectionResolver = createConnectionResolver(TYPENAME, testResolver);136 const connectionAttributesEdges = await connectionAttributes.edges();137 const resolverContext = { foo: 'bar' };138 expect.assertions(1 + connectionAttributesEdges.length);139 // Resolve the connection140 const resolvedConnection = builtConnectionResolver(connectionAttributes, resolverContext);141 const resolvedEdges = await resolvedConnection.edges();142 // Call all the nodes (i.e. 1), but we're leaving the generic expression143 // here in case the text changes144 await Promise.all(resolvedEdges.map(edge => edge.node()));145 // Resolver function must have been called as many times as edges there are146 expect(testResolver).toHaveBeenCalledTimes(resolvedEdges.length);147 // The resolver must been called with the correct arguments for each of the nodes148 // We don't care about the order.149 connectionAttributesEdges.forEach((connectionAttribute: any) =>150 expect(testResolver).toHaveBeenCalledWith(connectionAttribute.node(), resolverContext),151 );152 },153 );154 test('must properly wire edges().cursor() from the ' + 'connections function', async () => {155 const builtConnectionResolver = createConnectionResolver(TYPENAME, testResolver);156 const connectionAttributesEdges = await connectionAttributes.edges();157 expect.assertions(connectionAttributesEdges.length);158 // Resolve the connection159 const resolvedConnection = builtConnectionResolver(connectionAttributes);160 const resolvedEdges = await resolvedConnection.edges();161 // The resolver must been called with the correct arguments for each of the nodes162 // We don't care about the order.163 resolvedEdges.forEach(resolvedEdge => {164 // Because of this, this test is going to be O(n^2). Obviously we can165 // make it O(n) but using a dict. But n = 1 at this time.166 //167 // Does it really worth it overly-complicating this test in order to168 // decrease this test running time for bigger n? Not a this moment.169 const matchingConnectionEdge = connectionAttributesEdges.find(170 ({ node }: { node: () => { message: string } }) =>171 resolvedEdge.node().message === node().message,172 );173 if (!matchingConnectionEdge) {174 throw new Error(`Matching connection edge not found for resolved edge ${resolvedEdge}`);175 }176 expect(resolvedEdge.cursor).toBe(matchingConnectionEdge.cursor);177 });178 });179});180describe(resolve, () => {181 beforeEach(() => jest.clearAllMocks());182 // Need to create the mock resolver here, inside the closure, in order to183 // match the type signature of an actual created resolver.184 //185 // We could do this with createResolver(), yes, but this is a unit test, so186 // we shouldn't be involving that function here. Otherwise, this would become187 // an integration test.188 const testResolver = jest.fn(function testResolver({189 message,190 }: TestResolverInput): TestResolverOutput & ConnectionDecorator {191 return {192 __typename: 'Test',193 message,194 length: message.length,195 };196 });197 const resolverContext = { foo: 'bar' };198 test('must return null if attributes are not passed', () => {199 expect(200 resolve<TestResolverInput, TestResolverOutput>({201 attributes: null,202 using: testResolver,203 context: resolverContext,204 }),205 ).toBeNull();206 });207 test(208 'must call resolver as many times as elements are ' + 'passed on an array as attributes',209 () => {210 const TEST_ARRAY = [{ message: 'foo' }, { message: 'bar' }];211 resolve<TestResolverInput, TestResolverOutput>({212 attributes: TEST_ARRAY,213 using: testResolver,214 context: resolverContext,215 });216 TEST_ARRAY.forEach(element => {217 expect(testResolver).toHaveBeenCalledWith(element, resolverContext);218 });219 },220 );221 test('must return resolved values in the correct order', () => {222 // Might look like an integration test, but it is not. testResolver is223 // mocked on this describe() block.224 const TEST_ARRAY = [{ message: 'foo' }, { message: 'bar' }];225 const resolvedValues = resolve<TestResolverInput, TestResolverOutput>({226 attributes: TEST_ARRAY,227 using: testResolver,228 context: resolverContext,229 }) as TestResolverOutput[];230 TEST_ARRAY.forEach((element, i) => {231 expect(resolvedValues[i]).toEqual(testResolver(element, resolverContext));232 });233 });234 test(235 'must call resolver once, with correct arguments, when ' + 'a single element is passed',236 () => {237 const TEST_ATTRIBUTES = { message: 'foo' };238 resolve<TestResolverInput, TestResolverOutput>({239 attributes: TEST_ATTRIBUTES,240 using: testResolver,241 context: resolverContext,242 });243 expect(testResolver).toHaveBeenCalledTimes(1);244 expect(testResolver).toHaveBeenCalledWith(TEST_ATTRIBUTES, resolverContext);245 },246 );247 test('must return correct resolved value', () => {248 // Might look like an integration test, but it is not. testResolver is249 // mocked on this describe() block.250 const TEST_ATTRIBUTES = { message: 'foo' };251 const resolvedValue = resolve<TestResolverInput, TestResolverOutput>({252 attributes: TEST_ATTRIBUTES,253 using: testResolver,254 context: resolverContext,255 }) as TestResolverOutput;256 expect(resolvedValue).toEqual(testResolver(TEST_ATTRIBUTES, resolverContext));257 });...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1const Mocha = require("mocha");2const chai = require("chai");3const path = require("path");4const Web3 = require("web3");5const Config = require("truffle-config");6const Contracts = require("truffle-workflow-compile/new");7const Resolver = require("truffle-resolver");8const TestRunner = require("./testing/testrunner");9const TestResolver = require("./testing/testresolver");10const TestSource = require("./testing/testsource");11const SolidityTest = require("./testing/soliditytest");12const expect = require("truffle-expect");13const Migrate = require("truffle-migrate");14const Profiler = require("truffle-compile/profiler");15const originalrequire = require("original-require");16const Web3Shim = require("truffle-interface-adapter").Web3Shim;17chai.use(require("./assertions"));18const Test = {19 run: async function(options) {20 expect.options(options, [21 "contracts_directory",22 "contracts_build_directory",23 "migrations_directory",24 "test_files",25 "network",26 "network_id",27 "provider"28 ]);29 const config = Config.default().merge(options);30 config.test_files = config.test_files.map(testFile => {31 return path.resolve(testFile);32 });33 // `accounts` will be populated before each contract() invocation34 // and passed to it so tests don't have to call it themselves.35 const web3 = new Web3Shim({36 provider: config.provider,37 networkType: config.networks[config.network].type38 });39// const web3 = new Web3();40// web3.setProvider(config.provider);41 // Override console.warn() because web3 outputs gross errors to it.42 // e.g., https://github.com/ethereum/web3.js/blob/master/lib/web3/allevents.js#L6143 // Output looks like this during tests: https://gist.github.com/tcoulter/1988349d1ec65ce6b95844 const warn = config.logger.warn;45 config.logger.warn = message => {46 if (message === "cannot find event for log") {47 return;48 } else {49 if (warn) warn.apply(console, arguments);50 }51 };52 const mocha = this.createMocha(config);53 const jsTests = config.test_files.filter(file => {54 return path.extname(file) !== ".sol";55 });56 const solTests = config.test_files.filter(file => {57 return path.extname(file) === ".sol";58 });59 // Add Javascript tests because there's nothing we need to do with them.60 // Solidity tests will be handled later.61 jsTests.forEach(file => {62 // There's an idiosyncracy in Mocha where the same file can't be run twice63 // unless we delete the `require` cache.64 // https://github.com/mochajs/mocha/issues/99565 delete originalrequire.cache[file];66 mocha.addFile(file);67 });68 const accounts = await this.getAccounts(web3);69 if (!config.resolver) config.resolver = new Resolver(config);70 const testSource = new TestSource(config);71 const testResolver = new TestResolver(72 config.resolver,73 testSource,74 config.contracts_build_directory75 );76 testResolver.cache_on = false;77 const { compilations } = await this.compileContractsWithTestFilesIfNeeded(78 solTests,79 config,80 testResolver81 );82 const testContracts = solTests.map(testFilePath => {83 return testResolver.require(testFilePath);84 });85 const runner = new TestRunner(config);86 await this.performInitialDeploy(config, testResolver);87 await this.defineSolidityTests(88 mocha,89 testContracts,90 compilations.solc.sourceIndexes,91 runner92 );93 await this.setJSTestGlobals(web3, accounts, testResolver, runner);94 // Finally, run mocha.95 process.on("unhandledRejection", reason => {96 throw reason;97 });98 return new Promise(resolve => {99 mocha.run(failures => {100 config.logger.warn = warn;101 resolve(failures);102 });103 });104 },105 createMocha: function(config) {106 // Allow people to specify config.mocha in their config.107 var mochaConfig = config.mocha || {};108 // If the command line overrides color usage, use that.109 if (config.colors != null) {110 mochaConfig.useColors = config.colors;111 }112 // Default to true if configuration isn't set anywhere.113 if (mochaConfig.useColors == null) {114 mochaConfig.useColors = true;115 }116 var mocha = new Mocha(mochaConfig);117 return mocha;118 },119 getAccounts: function(web3) {120 return web3.eth.getAccounts();121 },122 compileContractsWithTestFilesIfNeeded: async function(123 solidityTestFiles,124 config,125 testResolver126 ) {127 const updated =128 (await Profiler.updated(config.with({ resolver: testResolver }))) || [];129 const compileConfig = config.with({130 all: config.compileAll === true,131 files: updated.concat(solidityTestFiles),132 resolver: testResolver,133 quiet: config.quiet,134 quietWrite: true135 });136 // Compile project contracts and test contracts137 const { contracts, compilations } = await Contracts.compile(compileConfig);138 await Contracts.save(compileConfig, contracts);139 return {140 contracts,141 compilations142 };143 },144 performInitialDeploy: function(config, resolver) {145 const migrateConfig = config.with({146 reset: true,147 resolver: resolver,148 quiet: true149 });150 return Migrate.run(migrateConfig);151 },152 defineSolidityTests: function(mocha, contracts, dependencyPaths, runner) {153 return new Promise(resolve => {154 contracts.forEach(contract => {155 SolidityTest.define(contract, dependencyPaths, runner, mocha);156 });157 resolve();158 });159 },160 setJSTestGlobals: function(web3, accounts, testResolver, runner) {161 return new Promise(function(accept) {162 global.web3 = web3;163 global.assert = chai.assert;164 global.expect = chai.expect;165 global.artifacts = {166 require: import_path => testResolver.require(import_path)167 };168 const template = function(tests) {169 this.timeout(runner.TEST_TIMEOUT);170 before("prepare suite", function(done) {171 this.timeout(runner.BEFORE_TIMEOUT);172 runner.initialize(done);173 });174 beforeEach("before test", function(done) {175 runner.startTest(this, done);176 });177 afterEach("after test", function(done) {178 runner.endTest(this, done);179 });180 tests(accounts);181 };182 global.contract = function(name, tests) {183 Mocha.describe("Contract: " + name, function() {184 template.bind(this, tests)();185 });186 };187 global.contract.only = function(name, tests) {188 Mocha.describe.only("Contract: " + name, function() {189 template.bind(this, tests)();190 });191 };192 global.contract.skip = function(name, tests) {193 Mocha.describe.skip("Contract: " + name, function() {194 template.bind(this, tests)();195 });196 };197 accept();198 });199 }200};...

Full Screen

Full Screen

deployment.test.js

Source:deployment.test.js Github

copy

Full Screen

1//const { assert } = require("chai");2const { web3tx } = require("@decentral.ee/web3-helpers");3const deployFramework = require("../scripts/deploy-framework");4const deployTestToken = require("../scripts/deploy-test-token");5const deploySuperToken = require("../scripts/deploy-super-token");6const TestResolver = artifacts.require("TestResolver");7const ISuperfluidGovernance = artifacts.require("ISuperfluidGovernance");8const Superfluid = artifacts.require("Superfluid");9contract("deployment test", () => {10 const errorHandler = err => { if (err) throw err; };11 it("codeChanged function", async () => {12 const ConstantFlowAgreementV1 = artifacts.require("ConstantFlowAgreementV1");13 const {14 codeChanged15 } = require("../scripts/utils");16 const a1 = await web3tx(ConstantFlowAgreementV1.new, "ConstantFlowAgreementV1.new 1")();17 assert.isFalse(await codeChanged(ConstantFlowAgreementV1, a1.address));18 });19 it("Deploy/upgrade/reset Superfluid Framework", async () => {20 const version = process.env.RELEASE_VERSION || "test";21 const superfluidName = `Superfluid.${version}`;22 const cfaName = `ConstantFlowAgreementV1.${version}`;23 const idaName = `InstantDistributionAgreementV1.${version}`;24 const govName = `TestGovernance.${version}`;25 const testResolver = await web3tx(TestResolver.new, "TestResolver.new")();26 delete process.env.RESET;27 process.env.TEST_RESOLVER_ADDRESS = testResolver.address;28 console.log("First deployment");29 await deployFramework(errorHandler);30 const superfluid1 = await testResolver.get(superfluidName);31 const gov1 = await testResolver.get(govName);32 const cfa1 = await testResolver.get(cfaName);33 const ida1 = await testResolver.get(idaName);34 assert.notEqual(superfluid1, "0x0000000000000000000000000000000000000000");35 assert.notEqual(gov1, "0x0000000000000000000000000000000000000000");36 assert.notEqual(cfa1, "0x0000000000000000000000000000000000000000");37 assert.notEqual(ida1, "0x0000000000000000000000000000000000000000");38 const gov1Contract = await ISuperfluidGovernance.at(gov1);39 assert.isTrue(await gov1Contract.isAgreementListed.call(cfa1));40 assert.isTrue(await gov1Contract.isAgreementListed.call(ida1));41 console.log("Upgrade logic contract");42 await deployFramework(errorHandler);43 const superfluid2 = await testResolver.get(superfluidName);44 const gov2 = await testResolver.get(govName);45 const cfa2 = await testResolver.get(cfaName);46 const ida2 = await testResolver.get(idaName);47 assert.equal(superfluid1, superfluid2);48 assert.equal(49 await (await Superfluid.at(superfluid1)).getCodeAddress(),50 await (await Superfluid.at(superfluid2)).getCodeAddress());51 assert.equal(gov1, gov2, "Governance deployment not required");52 assert.equal(cfa1, cfa2, "cfa deployment not required");53 assert.equal(ida1, ida2, "cfa deployment not required");54 console.log("Reset all");55 process.env.RESET = 1;56 await deployFramework(errorHandler);57 const superfluid3 = await testResolver.get(superfluidName);58 const gov3 = await testResolver.get(govName);59 const cfa3 = await testResolver.get(cfaName);60 const ida3 = await testResolver.get(idaName);61 assert.notEqual(superfluid3, "0x0000000000000000000000000000000000000000");62 assert.notEqual(gov3, "0x0000000000000000000000000000000000000000");63 assert.notEqual(cfa3, "0x0000000000000000000000000000000000000000");64 assert.notEqual(ida3, "0x0000000000000000000000000000000000000000");65 assert.notEqual(superfluid1, superfluid3);66 assert.notEqual(gov1, gov3);67 assert.notEqual(cfa1, cfa3);68 assert.notEqual(ida1, ida3);69 });70 it("Deployment without resolver", async () => {71 await deployFramework(errorHandler);72 });73 it("Deploy/upgrade/reset Super Token", async () => {74 const testResolver = await web3tx(TestResolver.new, "TestResolver.new")();75 delete process.env.RESET;76 process.env.TEST_RESOLVER_ADDRESS = testResolver.address;77 await deployFramework(errorHandler);78 await deployTestToken(errorHandler, [":", "TEST"]);79 await deploySuperToken(errorHandler, [":", "TEST"]);80 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2test("test", async () => {3 const browser = await qawolf.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await qawolf.scroll(page, "html", { x: 0, y: 0 });7 await qawolf.type(page, "#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input", "test");8 await qawolf.click(page, "#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input.gNO89b");9 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");10 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");11 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");12 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");13 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");14 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");15 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");16 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");17 await qawolf.click(page, "#rso > div:nth-child(1) > div > div > div > div > div.r > a > h3");18 await qawolf.click(page, "#rso > div:nth-child(1) > div > div >

Full Screen

Using AI Code Generation

copy

Full Screen

1const { testResolver } = require("qawolf");2const { test } = require("qawolf");3test("test", async () => {4 const browser = await testResolver();5 const page = await browser.newPage();6 await page.click('input[type="text"]');7 await page.fill('input[type="text"]', "Hello World");8 await page.click('input[type="submit"]');9 await page.click('div[class="g"] >> text="Hello World - Wikipedia"');10 await page.click('text="Hello World - Wikipedia"');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { testResolver } = require('qawolf');2const { testRunner } = require('qawolf');3const { createBrowser } = require('qawolf');4const { QA_WOLF_BROWSER } = process.env;5const browser = await createBrowser({ launchOptions: { headless: QA_WOLF_BROWSER !== 'true' } });6await testRunner(browser, testResolver(__filename));7const { testRunner } = require('qawolf');8const { testResolver } = require('qawolf');9const { createBrowser } = require('qawolf');10const { QA_WOLF_BROWSER } = process.env;11const browser = await createBrowser({ launchOptions: { headless: QA_WOLF_BROWSER !== 'true' } });12await testRunner(browser, testResolver(__filename));13const { testRunner } = require('qawolf');14const { testResolver } = require('qawolf');15const { createBrowser } = require('qawolf');16const { QA_WOLF_BROWSER } = process.env;17const browser = await createBrowser({ launchOptions: { headless: QA_WOLF_BROWSER !== 'true' } });18await testRunner(browser, testResolver(__filename));19const { testRunner } = require('qawolf');20const { testResolver } = require('qawolf');21const { createBrowser } = require('qawolf');22const { QA_WOLF_BROWSER } = process.env;23const browser = await createBrowser({ launchOptions: { headless: QA_WOLF_BROWSER !== 'true' } });24await testRunner(browser, testResolver(__filename));25const { testRunner } = require('qawolf');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { testResolver } = require("qawolf");2const { test, expect } = require("@playwright/test");3test("test", async ({ page }) => {4 await testResolver("test", page, "selector");5});6const { testResolver } = require("qawolf");7const { test, expect } = require("@playwright/test");8test("test", async ({ page }) => {9 await testResolver("test", page, "selector");10});11const { testResolver } = require("qawolf");12const { test, expect } = require("@playwright/test");13test("test", async ({ page }) => {14 await testResolver("test", page, "selector");15});16const { testResolver } = require("qawolf");17const { test, expect } = require("@playwright/test");18test("test", async ({ page }) => {19 await testResolver("test", page, "selector");20});21const { testResolver } = require("qawolf");22const { test, expect } = require("@playwright/test");23test("test", async ({ page }) => {24 await testResolver("test", page, "selector");25});26const { testResolver } = require("qawolf");27const { test, expect } = require("@playwright/test");28test("test", async ({ page }) => {29 await testResolver("test", page, "selector");30});31const { testResolver } = require("qawolf");32const { test, expect } = require("@playwright/test");33test("test", async ({ page }) => {34 await testResolver("test", page, "selector");35});36const { testResolver } = require("qawolf");37const { test, expect } = require("@playwright/test");38test("test

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful