Skip to content

Commit

Permalink
Merge branch 'master' into fix/build
Browse files Browse the repository at this point in the history
  • Loading branch information
CompuIves committed May 31, 2019
2 parents 61f0c98 + 6a76495 commit 01ccbab
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 127 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,15 @@
"contributions": [
"code"
]
},
{
"login": "batiskafff",
"name": "Yehor",
"avatar_url": "https://avatars3.githubusercontent.com/u/1769092?v=4",
"profile": "https://github.com/batiskafff",
"contributions": [
"code"
]
}
],
"repoType": "github",
Expand Down
4 changes: 2 additions & 2 deletions README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"codesandbox-import-utils": "2.1.2",
"color": "^0.11.4",
"compare-versions": "^3.1.0",
"console": "^0.7.2",
"console-feed": "^2.8.5",
"css-modules-loader-core": "^1.1.0",
"cssnano": "^3.10.0",
Expand Down Expand Up @@ -192,6 +193,7 @@
"instantsearch.css": "^7.1.0",
"is-url": "^1.2.2",
"jest-circus": "^22.1.4",
"jest-each": "^24.8.0",
"jest-snapshot": "^22.1.2",
"jszip": "^3.1.3",
"localforage": "^1.5.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import TestDetailsContent from './TestDetails';
import TestSummary from './TestSummary';
import TestOverview from './TestOverview';
import { DevToolProps } from '..';
import { messages } from './../../../../../../src/sandbox/eval/tests/jest-lite';

export type IMessage = {
type: 'message' | 'command' | 'return';
Expand Down Expand Up @@ -80,7 +81,7 @@ type SandboxMessage = { type: 'test' | 'done' } & (
| TestEndMessage);

interface InitializedTestsMessage {
event: 'initialize_tests';
event: messages.INITIALIZE;
}

interface TestCountMessage {
Expand Down Expand Up @@ -203,7 +204,7 @@ class Tests extends React.Component<DevToolProps, State> {
this.runAllTests();
} else if (data.type === 'test') {
switch (data.event) {
case 'initialize_tests': {
case messages.INITIALIZE: {
this.currentDescribeBlocks = [];
if (this.props.updateStatus) {
this.props.updateStatus('clear');
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/app/store/modules/deployment/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export async function createApiData({ props, state }) {
apiData.builds = nowJSON.builds;
apiData.routes = nowJSON.routes;
apiData.env = nowJSON.env;
apiData.scope = nowJSON.scope;
apiData['build.env'] = nowJSON['build.env'];
apiData.regions = nowJSON.regions;
} else {
Expand Down
203 changes: 107 additions & 96 deletions packages/app/src/sandbox/eval/tests/jest-lite.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// import TestRunner from './jest-lite';
const TestRunner = {};
import TestRunner, { messages } from './jest-lite';

describe.skip('TestRunner class', () => {
jest.mock('sandbox-hooks/react-error-overlay/utils/mapper', () => {
return {
map: jest.fn(),
};
});

jest.mock('codesandbox-api');
const api = require('codesandbox-api');

api.dispatch = jest.fn();

describe('TestRunner class', () => {
it('exports a module', () => {
expect(TestRunner).toEqual(expect.any(Function));
});
Expand All @@ -13,63 +23,65 @@ describe.skip('TestRunner class', () => {
});

describe('initialize', () => {
it('should reset results', () => {
const testRunner = new TestRunner();
expect(testRunner.aggregatedResults.totalTests).toBe(0);
testRunner.addResult({ status: 'pass', name: 'foo' });
expect(testRunner.aggregatedResults.totalTests).toBe(1);
testRunner.initialize();
expect(testRunner.aggregatedResults.totalTests).toBe(0);
let testRunner;
beforeEach(() => {
TestRunner.sendMessage = jest.fn();
testRunner = new TestRunner();
});

it('should be created with 0 test ran', () => {
expect(testRunner.ranTests.size).toBe(0);
});

it('should send message (dispatch) on initilaization', () => {
expect(api.dispatch).toHaveBeenCalledWith({
type: 'test',
event: messages.INITIALIZE,
});
});
});

describe('testGlobals', () => {
it('returns an object', () => {
let {
describe: _describe,
it('returns an object', async () => {
const testRunner = new TestRunner();

window.fetch = jest.fn();
window.localStorage = jest.fn();

await testRunner.initJSDOM();

const {
it: _it,
test: _test,
expect: _expect,
jest: _jest,
} = new TestRunner().testGlobals();

expect(_describe).toEqual(expect.any(Function));
expect(_it).toEqual(expect.any(Function));
expect(_test).toEqual(expect.any(Function));
expect(_expect).toEqual(expect.any(Function));
expect(_jest).toEqual(expect.any(Object));
document: _document,
window: _window,
global: _global,
} = testRunner.testGlobals();

expect(_it).toBeInstanceOf(Function);
expect(_test).toBeInstanceOf(Function);
expect(_expect).toBeInstanceOf(Function);
expect(_jest).toBeInstanceOf(Object);
expect(_document).toBeInstanceOf(Object);
expect(_window).toBeInstanceOf(Object);
expect(_global).toBeInstanceOf(Object);
});

describe('describe', () => {
let testRunner;
let _describe;
let fnSpy;

beforeAll(() => {
testRunner = new TestRunner();
_describe = testRunner.testGlobals().describe;
fnSpy = jest.fn();
});

it('calls the function block', () => {
_describe('foo', fnSpy);
expect(fnSpy).toHaveBeenCalled();
});
});

describe('test', () => {
xdescribe('test', () => {
let testRunner;
let _test;
let fnSpy;

beforeEach(() => {
beforeEach(async () => {
testRunner = new TestRunner();
await testRunner.initJSDOM();
_test = testRunner.testGlobals().test;
fnSpy = jest.fn();
});

it('calls the function block', () => {
_test('foo', fnSpy);
expect(fnSpy).toHaveBeenCalled();
});

Expand Down Expand Up @@ -97,50 +109,58 @@ describe.skip('TestRunner class', () => {
});

it('should be initialized with no tests', () => {
expect(testRunner.tests).toEqual([]);
expect(testRunner.ranTests.size).toBe(0);
});
it('should not find any tests when no modules are passed', () => {
testRunner.findTests([]);
testRunner.findTests({});
expect(testRunner.tests).toEqual([]);
});

it('should find tests when modules are passed', () => {
testRunner.findTests([{ path: 'Sum.test.js' }]);
it('should find 1 test when modules are passed', () => {
testRunner.findTests({ 'Sum.test.js': { path: 'Sum.test.js' } });
expect(testRunner.tests).toHaveLength(1);
});

testRunner.findTests([
{ path: 'Sum.test.js' },
{ path: 'Sum.spec.js' },
{ path: '__tests__/Sum.js' },
{ path: 'Sum.js' },
{ path: 'src/Sum.js' },
{ path: 'src/Sum.js' },
]);
it('should find 3 of 6 tests when modules are passed', () => {
testRunner.findTests({
'Sum.test.js': { path: 'Sum.test.js' },
'Sum.spec.js': { path: 'Sum.spec.js' },
'__tests__/Sum.js': { path: '__tests__/Sum.js' },
'Sum.js': { path: 'Sum.js' },
'src/Sum.js': { path: 'src/Sum.js' },
'src/Sum.js1': { path: 'src/Sum.js1' },
});
expect(testRunner.tests).toHaveLength(3);
});

testRunner.findTests([
{ path: 'Sum.test.ts' },
{ path: 'Sum.spec.ts' },
{ path: '__tests__/Sum.ts' },
{ path: 'Sum.ts' },
{ path: 'src/Sum.ts' },
]);
it('should find 3 of 5 tests when modules are passed', () => {
testRunner.findTests({
'Sum.test.ts': { path: 'Sum.test.ts' },
'Sum.spec.ts': { path: 'Sum.spec.ts' },
'__tests__/Sum.ts': { path: '__tests__/Sum.ts' },
'Sum.ts': { path: 'Sum.ts' },
'src/Sum.ts': { path: 'src/Sum.ts' },
});
expect(testRunner.tests).toHaveLength(3);
});

testRunner.findTests([
{ path: 'Sum.test.tsx' },
{ path: 'Sum.spec.tsx' },
{ path: '__tests__/Sum.tsx' },
{ path: 'Sum.tsx' },
{ path: 'src/Sum.tsx' },
]);
it('should find 3 of 5 (typescript) tests when modules are passed', () => {
testRunner.findTests({
'Sum.test.tsx': { path: 'Sum.test.tsx' },
'Sum.spec.tsx': { path: 'Sum.spec.tsx' },
'__tests__/Sum.tsx': { path: '__tests__/Sum.tsx' },
'Sum.tsx': { path: 'Sum.tsx' },
'src/Sum.tsx': { path: 'src/Sum.tsx' },
});
expect(testRunner.tests).toHaveLength(3);
});

testRunner.findTests([
{ path: 'Sum.test.js' },
{ path: 'Sum.test.ts' },
{ path: 'Sum.test.tsx' },
]);
it('should find 3 of 3 tests when modules are passed', () => {
testRunner.findTests({
'Sum.test.js': { path: 'Sum.test.js' },
'Sum.test.ts': { path: 'Sum.test.ts' },
'Sum.test.tsx': { path: 'Sum.test.tsx' },
});
expect(testRunner.tests).toHaveLength(3);
});
});
Expand All @@ -153,24 +173,14 @@ describe.skip('TestRunner class', () => {
it('todo');
});

describe('addResult', () => {
// deprecated
xdescribe('addResult', () => {
let testRunner;

beforeEach(() => {
testRunner = new TestRunner();
});

it('should start off with no test results', () => {
expect(testRunner.aggregatedResults).toMatchObject({
failedTestSuites: 0,
passedTestSuites: 0,
totalTestSuites: 0,
failedTests: 0,
passedTests: 0,
totalTests: 0,
});
});

it('should add pass test results', () => {
testRunner.addResult({ status: 'pass', name: 'foo' });
testRunner.addResult({ status: 'pass', name: 'bar' });
Expand Down Expand Up @@ -232,7 +242,8 @@ describe.skip('TestRunner class', () => {
});
});

describe('reportResults', () => {
// deprecated
xdescribe('reportResults', () => {
let testRunner;

beforeEach(() => {
Expand All @@ -247,8 +258,8 @@ describe.skip('TestRunner class', () => {
testRunner.addResult({ status: 'pass', name: 'foo' });
testRunner.addResult({ status: 'pass', name: 'bar' });

let results = testRunner.reportResults();
let { summaryMessage } = results;
const results = testRunner.reportResults();
const { summaryMessage } = results;

expect(results).not.toEqual(null);
expect(summaryMessage).toMatch(/Test Summary: 😎/);
Expand All @@ -262,8 +273,8 @@ describe.skip('TestRunner class', () => {
testRunner.addResult({ status: 'fail', name: 'foo' });
testRunner.addResult({ status: 'fail', name: 'bar' });

let results = testRunner.reportResults();
let { summaryMessage, failedMessages } = results;
const results = testRunner.reportResults();
const { summaryMessage, failedMessages } = results;

expect(results).not.toEqual(null);
expect(summaryMessage).toMatch(/Test Summary: 👻/);
Expand All @@ -290,8 +301,8 @@ describe.skip('TestRunner class', () => {
testRunner.addResult({ status: 'pass', name: 'foo' });
testRunner.addResult({ status: 'fail', name: 'bar' });

let results = testRunner.reportResults();
let { summaryMessage } = results;
const results = testRunner.reportResults();
const { summaryMessage } = results;

expect(results).not.toEqual(null);
expect(summaryMessage).toMatch(/Test Summary: 👻/);
Expand All @@ -318,8 +329,8 @@ describe.skip('TestRunner class', () => {
testRunner.setCurrentDescribe('bar');
testRunner.addResult({ status: 'fail', name: 'baz' });

let results = testRunner.reportResults();
let { failedMessages } = results;
const results = testRunner.reportResults();
const { failedMessages } = results;

expect(results).not.toEqual(null);
expect(failedMessages[0]).toMatch(/FAIL/);
Expand All @@ -331,8 +342,8 @@ describe.skip('TestRunner class', () => {
testRunner.addResult({ status: 'pass', name: 'bar' });
testRunner.addResult({ status: 'fail', name: 'baz' });

let results = testRunner.reportResults();
let { summaryMessage } = results;
const results = testRunner.reportResults();
const { summaryMessage } = results;

expect(results).not.toEqual(null);
expect(summaryMessage).toMatch(/Test Summary: 👻/);
Expand All @@ -353,8 +364,8 @@ describe.skip('TestRunner class', () => {
testRunner.addResult({ status: 'pass', name: 'foo' });
testRunner.addResult({ status: 'fail', name: 'bar' });

let results = testRunner.reportResults();
let { summaryMessage } = results;
const results = testRunner.reportResults();
const { summaryMessage } = results;

expect(results).not.toEqual(null);
expect(summaryMessage).toMatch(/Test Summary: 👻/);
Expand Down
Loading

0 comments on commit 01ccbab

Please sign in to comment.