Skip to content

Commit

Permalink
Do not leak client functions into global scope
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Sep 6, 2021
1 parent 85e1eec commit e55763d
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 212 deletions.
10 changes: 10 additions & 0 deletions cli/test/fixture/client-leak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*eslint-env mocha*/
'use strict';

describe('test', () => {
it('does not leak client functions into global scope', () => {
if (typeof MochifyReporter !== 'undefined') {
throw new Error('MochifyReporter leaked');
}
});
});
43 changes: 24 additions & 19 deletions cli/test/jsdom.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ const { assert } = require('@sinonjs/referee-sinon');
const execa = require('execa');

describe('jsdom', () => {
it('passes', async () => {
const result = await execa(
'../../index.js',
['--driver', 'jsdom', 'passes.js'],
{
async function run(file) {
try {
return await execa('../../index.js', ['--driver', 'jsdom', file], {
cwd: path.join(__dirname, 'fixture')
}
);
});
} catch (error) {
return error;
}
}

it('passes', async () => {
const result = await run('passes.js');

assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
Expand All @@ -21,22 +25,23 @@ describe('jsdom', () => {
});

it('fails', async () => {
let result;
try {
result = await execa(
'../../index.js',
['--driver', 'jsdom', 'fails.js'],
{
cwd: path.join(__dirname, 'fixture')
}
);
} catch (error) {
result = error;
}
const result = await run('fails.js');

assert.isTrue(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(json.tests[0].fullTitle, 'test fails');
});

it('does not leak client functions into global scope', async () => {
const result = await run('client-leak.js');

assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(
json.tests[0].fullTitle,
'test does not leak client functions into global scope'
);
});
});
59 changes: 28 additions & 31 deletions cli/test/playwright.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ const { assert } = require('@sinonjs/referee-sinon');
const execa = require('execa');

describe('playwright', () => {
async function run(file) {
try {
return await execa(
'../../index.js',
['--driver', 'playwright', '--driver-option.engine', 'chromium', file],
{
cwd: path.join(__dirname, 'fixture')
}
);
} catch (error) {
return error;
}
}

it('passes', async () => {
const result = await execa(
'../../index.js',
[
'--driver',
'playwright',
'--driver-option.engine',
'chromium',
'passes.js'
],
{
cwd: path.join(__dirname, 'fixture')
}
);
const result = await run('passes.js');

assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
Expand All @@ -27,28 +29,23 @@ describe('playwright', () => {
});

it('fails', async () => {
let result;
try {
result = await execa(
'../../index.js',
[
'--driver',
'playwright',
'--driver-option.engine',
'chromium',
'fails.js'
],
{
cwd: path.join(__dirname, 'fixture')
}
);
} catch (error) {
result = error;
}
const result = await run('fails.js');

assert.isTrue(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(json.tests[0].fullTitle, 'test fails');
});

it('does not leak client functions into global scope', async () => {
const result = await run('client-leak.js');

assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(
json.tests[0].fullTitle,
'test does not leak client functions into global scope'
);
});
});
43 changes: 24 additions & 19 deletions cli/test/puppeteer.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ const { assert } = require('@sinonjs/referee-sinon');
const execa = require('execa');

describe('puppeteer', () => {
it('passes', async () => {
const result = await execa(
'../../index.js',
['--driver', 'puppeteer', 'passes.js'],
{
async function run(file) {
try {
return await execa('../../index.js', ['--driver', 'puppeteer', file], {
cwd: path.join(__dirname, 'fixture')
}
);
});
} catch (error) {
return error;
}
}

it('passes', async () => {
const result = await run('passes.js');

assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
Expand All @@ -21,22 +25,23 @@ describe('puppeteer', () => {
});

it('fails', async () => {
let result;
try {
result = await execa(
'../../index.js',
['--driver', 'puppeteer', 'fails.js'],
{
cwd: path.join(__dirname, 'fixture')
}
);
} catch (error) {
result = error;
}
const result = await run('fails.js');

assert.isTrue(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(json.tests[0].fullTitle, 'test fails');
});

it('does not leak client functions into global scope', async () => {
const result = await run('client-leak.js');

assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(
json.tests[0].fullTitle,
'test does not leak client functions into global scope'
);
});
});
Loading

0 comments on commit e55763d

Please sign in to comment.