Skip to content

Commit

Permalink
Merge branch 'pa/tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
benzino77 committed Sep 22, 2021
2 parents 6257d36 + f84d63a commit 7f7be62
Show file tree
Hide file tree
Showing 15 changed files with 2,675 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ image:
file: .gitpod.Dockerfile
tasks:
- init: yarn install
command: yarn build && pip3 install platformio && node server/server.js
command: yarn build && pip3 install platformio && node server/app.js
ports:
- port: 3000
onOpen: open-browser
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ RUN cd /tasmocompiler && yarn install && \
yarn cache clean
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8
WORKDIR /tasmocompiler
ENTRYPOINT ["nodemon", "server/server.js"]
ENTRYPOINT ["nodemon", "server/app.js"]
39 changes: 39 additions & 0 deletions __mocks__/fs-extra.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = jest.genMockFromModule('fs-extra');

let fsStatReject = true;
let fsRemoveReject = true;
let retFsPathExistsSync = false;

function __setFsStatReject(reject) {
fsStatReject = reject;
}

function __setFsRemoveReject(reject) {
fsRemoveReject = reject;
}

function __setRetFsPathExistsSync(value) {
retFsPathExistsSync = value;
}

fs.__setFsStatReject = __setFsStatReject;
fs.__setFsRemoveReject = __setFsRemoveReject;
fs.__setRetFsPathExistsSync = __setRetFsPathExistsSync;

fs.stat = jest.fn((path) => {
if (fsStatReject) {
return Promise.reject();
}
return Promise.resolve();
});

fs.remove = jest.fn((path) => {
if (fsRemoveReject) return Promise.reject();
return Promise.resolve();
});

fs.pathExistsSync = jest.fn((path) => {
return retFsPathExistsSync;
});

module.exports = fs;
110 changes: 110 additions & 0 deletions __mocks__/simple-git/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
let gitIsRepoRet = true;
let gitTagsReject = true;
let gitCloneReject = true;
let gitPullReject = true;
let gitResetReject = true;
let gitCleanReject = true;
let gitBranchLocalReject = true;
let gitCheckoutBranchReject = true;
let gitCheckoutReject = true;
let retTags = [];
let retLocalBranches = {};

function __setGitIsRepoRet(value) {
gitIsRepoRet = value;
}

function __setRepoTags(tags) {
retTags = tags;
}

function __setGitTagsReject(reject) {
gitTagsReject = reject;
}

function __setGitCloneReject(reject) {
gitCloneReject = reject;
}

function __setGitPullReject(reject) {
gitPullReject = reject;
}

function __setGitResetReject(reject) {
gitResetReject = reject;
}

function __setGitCleanReject(reject) {
gitCleanReject = reject;
}

function __setGitBranchLocalReject(reject) {
gitBranchLocalReject = reject;
}

function __setLocalBranches(branches) {
retLocalBranches = branches;
}

function __setGitCheckoutBranchReject(reject) {
gitCheckoutBranchReject = reject;
}

function __setGitCheckoutReject(reject) {
gitCheckoutReject = reject;
}

const gitObject = {
checkIsRepo: jest.fn(() => Promise.resolve(gitIsRepoRet)),
tags: jest.fn(() => {
if (gitTagsReject) return Promise.reject();
return Promise.resolve({ all: retTags });
}),
clone: jest.fn((source, dest) => {
if (gitCloneReject) return Promise.reject();

return Promise.resolve();
}),
pull: jest.fn(() => {
if (gitPullReject) return Promise.reject();
return Promise.resolve();
}),
reset: jest.fn((type) => {
if (gitResetReject) return Promise.reject();
return Promise.resolve();
}),
clean: jest.fn((opts) => {
if (gitCleanReject) return Promise.reject();
return Promise.resolve();
}),
branchLocal: jest.fn(() => {
if (gitBranchLocalReject) return Promise.reject();
return Promise.resolve({ branches: retLocalBranches });
}),
checkoutBranch: jest.fn((remote, local) => {
if (gitCheckoutBranchReject) return Promise.reject();
return Promise.resolve();
}),
checkout: jest.fn(() => {
if (gitCheckoutReject) return Promise.reject();
return Promise.resolve();
}),
};

const git = jest.fn((path) => {
return gitObject;
});

git.__setGitIsRepoRet = __setGitIsRepoRet;
git.__setRepoTags = __setRepoTags;
git.__setGitTagsReject = __setGitTagsReject;
git.__setGitCloneReject = __setGitCloneReject;
git.__setGitPullReject = __setGitPullReject;
git.__setGitResetReject = __setGitResetReject;
git.__setGitCleanReject = __setGitCleanReject;
git.__setGitBranchLocalReject = __setGitBranchLocalReject;
git.__setLocalBranches = __setLocalBranches;
git.__setGitCheckoutBranchReject = __setGitCheckoutBranchReject;
git.__setGitCheckoutReject = __setGitCheckoutReject;

module.exports = git;
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');

module.exports = {
verbose: true,
collectCoverage: true,
setupFiles: [path.resolve(__dirname, 'jestSetEnv.js')],
};
2 changes: 2 additions & 0 deletions jestSetEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
process.env.WORKDIR = '/tmp/serverTest';
// process.env.DEBUG = 'server,git,compile';
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tasmocompiler",
"version": "6.0.0",
"version": "6.0.1",
"private": true,
"proxy": "http://localhost:3001/",
"dependencies": {
Expand All @@ -26,9 +26,10 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --env=jsdom-fourteen",
"testbackend": "jest server/ ",
"eject": "react-scripts eject",
"startdev": "concurrently --kill-others \"PORT=3001 DEBUG=\"server,git,compile\" nodemon server/server.js\" \"yarn start\""
"startdev": "concurrently --kill-others \"PORT=3001 DEBUG=\"server,git,compile\" nodemon server/app.js\" \"yarn start\""
},
"browserslist": [
">0.2%",
Expand All @@ -37,12 +38,17 @@
"not op_mini all"
],
"devDependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"concurrently": "^4.1.0",
"eslint": "5.12.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-react": "7.12.4",
"nodemon": "^2.0.2"
"jest-environment-jsdom-fourteen": "^1.0.1",
"msw": "^0.32.0",
"nodemon": "^2.0.2",
"supertest": "^6.1.3"
}
}
6 changes: 6 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { server } = require('./server');
const { listenPort } = require('./config/config');

server.listen(listenPort, () => {
console.log(`Server started on port ${listenPort}`);
});
11 changes: 11 additions & 0 deletions server/compile/__test__/compile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fsMock = require('fs-extra');
const { compileCode } = require('../compile');

describe('compile.js test', () => {
describe('testing getImageName', () => {
it('should return empty string if file with current image cannot be found', async (done) => {
const define = await compileCode('socket', 'board');
done();
});
});
});
Loading

0 comments on commit 7f7be62

Please sign in to comment.