mirror of
https://github.com/morten-olsen/react-native-debug-console.git
synced 2026-02-08 00:36:26 +01:00
Initial test setup
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
tests/coverage
|
||||||
@@ -32,12 +32,12 @@ const theme = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Wrapper = styled.View``;
|
const Wrapper = styled.View``;
|
||||||
const List = styled.View`
|
export const List = styled.View`
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
border-left-width: 10px;
|
border-left-width: 10px;
|
||||||
border-color: ${props => props.color || 'black' }
|
border-color: ${props => props.color || 'black' }
|
||||||
`;
|
`;
|
||||||
const Row = styled.View`
|
export const Row = styled.View`
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export const proxyConsole = window.console;
|
export const proxyConsole = global.console;
|
||||||
|
|
||||||
class Log {
|
class Log {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const proxied = window.XMLHttpRequest.prototype.open;
|
const proxied = global.XMLHttpRequest ? global.XMLHttpRequest.prototype.open : () => {};
|
||||||
let currentId = 0;
|
let currentId = 0;
|
||||||
|
|
||||||
class Network {
|
class Network {
|
||||||
@@ -46,7 +46,7 @@ class Network {
|
|||||||
attach() {
|
attach() {
|
||||||
const me = this;
|
const me = this;
|
||||||
const headers = {};
|
const headers = {};
|
||||||
window.XMLHttpRequest.prototype.open = function proxyOpen (...args) {
|
global.XMLHttpRequest.prototype.open = function proxyOpen (...args) {
|
||||||
let sendArgs;
|
let sendArgs;
|
||||||
const [
|
const [
|
||||||
method,
|
method,
|
||||||
@@ -100,7 +100,7 @@ class Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
detach() {
|
detach() {
|
||||||
window.XMLHttpRequest.prototype.open = proxied;
|
global.XMLHttpRequest.prototype.open = proxied;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"demo",
|
"demo",
|
||||||
"lib"
|
"lib",
|
||||||
|
"tests"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "lerna bootstrap",
|
"postinstall": "lerna bootstrap",
|
||||||
|
|||||||
2
tests/__mocks__/react.js
vendored
Normal file
2
tests/__mocks__/react.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
const React = require('react')
|
||||||
|
module.exports = { ...React, useEffect: React.useLayoutEffect }
|
||||||
13
tests/babel.config.js
Normal file
13
tests/babel.config.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = function(api) {
|
||||||
|
api.cache(true);
|
||||||
|
return {
|
||||||
|
presets: ['babel-preset-expo'],
|
||||||
|
plugins: [
|
||||||
|
[require.resolve('babel-plugin-module-resolver'), {
|
||||||
|
alias: {
|
||||||
|
'@babel/runtime': '../node_modules/@babel/runtime',
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
};
|
||||||
4
tests/jest.config.js
Normal file
4
tests/jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: "react-native",
|
||||||
|
rootDir: '..',
|
||||||
|
};
|
||||||
13
tests/package.json
Normal file
13
tests/package.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "tests",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "^24.8.0",
|
||||||
|
"react-test-renderer": "^16.8.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
47
tests/src/Console.spec.js
Normal file
47
tests/src/Console.spec.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import getDevTools from './getDevTools';
|
||||||
|
import renderer from 'react-test-renderer';
|
||||||
|
|
||||||
|
describe('Console', () => {
|
||||||
|
describe('output', () => {
|
||||||
|
let devTool;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
devTool = getDevTools();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render an emptry list', () => {
|
||||||
|
expect(devTool.console.output().props.logs).toEqual([
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render one item', () => {
|
||||||
|
renderer.act(() => {
|
||||||
|
devTool.log.add('test');
|
||||||
|
});
|
||||||
|
expect(devTool.console.output().props.logs).toEqual([
|
||||||
|
'test',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render multible items item', () => {
|
||||||
|
renderer.act(() => {
|
||||||
|
devTool.log.add('1');
|
||||||
|
devTool.log.add('2');
|
||||||
|
devTool.log.add('3');
|
||||||
|
devTool.log.add('4');
|
||||||
|
devTool.log.add('5');
|
||||||
|
devTool.log.add('6');
|
||||||
|
devTool.log.add('7');
|
||||||
|
});
|
||||||
|
expect(devTool.console.output().props.logs).toEqual([
|
||||||
|
'1',
|
||||||
|
'2',
|
||||||
|
'3',
|
||||||
|
'4',
|
||||||
|
'5',
|
||||||
|
'6',
|
||||||
|
'7',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
61
tests/src/getDevTools.js
Normal file
61
tests/src/getDevTools.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import renderer from 'react-test-renderer';
|
||||||
|
import {
|
||||||
|
DevTool,
|
||||||
|
} from 'react-native-debug-console';
|
||||||
|
import Console from 'react-native-debug-console/src/components/DevTool/Console';
|
||||||
|
import ConsoleOutput, { Row as OutputRow} from 'react-native-debug-console/src/components/DevTool/Console/Output';
|
||||||
|
import ConsoleInput from 'react-native-debug-console/src/components/DevTool/Console/Input';
|
||||||
|
|
||||||
|
import Requests from 'react-native-debug-console/src/components/DevTool/Requests';
|
||||||
|
import RequestsDetails from 'react-native-debug-console/src/components/DevTool/Requests/Details';
|
||||||
|
import RequestsList from 'react-native-debug-console/src/components/DevTool/Requests/List';
|
||||||
|
|
||||||
|
import Storage from 'react-native-debug-console/src/components/DevTool/Storage';
|
||||||
|
import StorageKeys from 'react-native-debug-console/src/components/DevTool/Storage/Keys';
|
||||||
|
import StorageValues from 'react-native-debug-console/src/components/DevTool/Storage/Value';
|
||||||
|
|
||||||
|
const createLog = () => {
|
||||||
|
const listeners = [];
|
||||||
|
const logs = [];
|
||||||
|
return {
|
||||||
|
listen: (l) => listeners.push(l),
|
||||||
|
unlisten: (l) => listeners = listeners.filter(nl => nl !== l),
|
||||||
|
add: (log) => {
|
||||||
|
logs.push(log);
|
||||||
|
listeners.forEach(l => l(logs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getDevTools = () => {
|
||||||
|
const log = createLog();
|
||||||
|
const instance = renderer.create(
|
||||||
|
<DevTool
|
||||||
|
logProvider={log}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
const result = {
|
||||||
|
instance,
|
||||||
|
console: {
|
||||||
|
main: () => instance.root.findByType(Console),
|
||||||
|
output: () => instance.root.findByType(ConsoleOutput),
|
||||||
|
rows: () => instance.root.findAllByType(OutputRow),
|
||||||
|
input: () => instance.root.findByType(ConsoleInput),
|
||||||
|
},
|
||||||
|
requests: {
|
||||||
|
main: () => instance.root.findByType(Requests),
|
||||||
|
output: () => instance.root.findByType(RequestsDetails),
|
||||||
|
input: () => instance.root.findByType(RequestsList),
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
main: () => instance.root.findByType(Storage),
|
||||||
|
output: () => instance.root.findByType(StorageKeys),
|
||||||
|
input: () => instance.root.findByType(StorageValues),
|
||||||
|
},
|
||||||
|
log,
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getDevTools;
|
||||||
3548
tests/yarn.lock
Normal file
3548
tests/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user