mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-12-27 09:29:10 +00:00
Merge pull request #42 from cse110-fa22-group29/js-linting-ci
Implement JS linting framework and action
This commit is contained in:
commit
d6e8291779
33
.eslintrc.json
Normal file
33
.eslintrc.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es2021": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"overrides": [
|
||||||
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": "latest",
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"indent": [
|
||||||
|
"error",
|
||||||
|
"tab"
|
||||||
|
],
|
||||||
|
"linebreak-style": [
|
||||||
|
"error",
|
||||||
|
"unix"
|
||||||
|
],
|
||||||
|
"quotes": [
|
||||||
|
"error",
|
||||||
|
"double"
|
||||||
|
],
|
||||||
|
"semi": [
|
||||||
|
"error",
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"no-global-assign": 0
|
||||||
|
}
|
||||||
|
}
|
25
.github/workflows/js-linting.yml
vendored
Normal file
25
.github/workflows/js-linting.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: JS Linting
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Single deploy job since we're just deploying
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install apt updates
|
||||||
|
run: sudo apt -y update; sudo apt -y upgrade;
|
||||||
|
- name: Install prerequisites
|
||||||
|
run: sudo apt install -y nodejs npm;
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Install dependencies
|
||||||
|
run: sudo npm install
|
||||||
|
- name: Run tests
|
||||||
|
run: sudo npm run lint
|
2
.github/workflows/js-unittest.yml
vendored
2
.github/workflows/js-unittest.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: Jest JS Unit Test
|
name: JS Unit Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
"name": "food-journal",
|
"name": "food-journal",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --recursive **/*.test.js"
|
"test": "mocha --recursive **/*.test.js",
|
||||||
|
"lint": "eslint **/*.js",
|
||||||
|
"fix-style": "eslint --fix **/*.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"devDependencies": {
|
||||||
|
"eslint": "^8.27.0",
|
||||||
"mocha": "10"
|
"mocha": "10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
module.exports = {environment};
|
module.exports = {environment};
|
||||||
|
|
||||||
function environment () {
|
function environment () {
|
||||||
const localStorageMock = (function () {
|
const localStorageMock = (function () {
|
||||||
let store = {};
|
let store = {};
|
||||||
return {
|
return {
|
||||||
getItem(key) {
|
getItem(key) {
|
||||||
return store[key];
|
return store[key];
|
||||||
},
|
},
|
||||||
setItem(key, value) {
|
setItem(key, value) {
|
||||||
store[key] = value;
|
store[key] = value;
|
||||||
},
|
},
|
||||||
clear() {
|
clear() {
|
||||||
store = {};
|
store = {};
|
||||||
},
|
},
|
||||||
removeItem(key) {
|
removeItem(key) {
|
||||||
delete store[key];
|
delete store[key];
|
||||||
},
|
},
|
||||||
getAll() {
|
getAll() {
|
||||||
return store;
|
return store;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
let window = {};
|
let window = {};
|
||||||
Object.defineProperty(window, "localStorage", { value: localStorageMock });
|
Object.defineProperty(window, "localStorage", { value: localStorageMock });
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
@ -1,80 +1,81 @@
|
|||||||
const {environment} = require("./testenv.js");
|
const {environment} = require("./testenv.js");
|
||||||
var assert = require('assert');
|
var assert = require("assert");
|
||||||
var {saveToLocal, getFromLocal, removeFromLocal, clearLocal} = require('./testenv_helpers');
|
var {describe, it, beforeEach} = require("mocha");
|
||||||
|
var {saveToLocal, getFromLocal, removeFromLocal, clearLocal} = require("./testenv_helpers");
|
||||||
beforeEach(() => {
|
|
||||||
window = environment();
|
beforeEach(() => {
|
||||||
});
|
window = environment();
|
||||||
|
});
|
||||||
describe("test localStorage mock", () => {
|
|
||||||
it("test save and fetch", () => {
|
describe("test localStorage mock", () => {
|
||||||
saveToLocal("testkey1", "testvalue1");
|
it("test save and fetch", () => {
|
||||||
saveToLocal("testkey2", "testvalue2");
|
saveToLocal("testkey1", "testvalue1");
|
||||||
saveToLocal("testkey3", "testvalue3");
|
saveToLocal("testkey2", "testvalue2");
|
||||||
saveToLocal("testkey4", "testvalue4");
|
saveToLocal("testkey3", "testvalue3");
|
||||||
|
saveToLocal("testkey4", "testvalue4");
|
||||||
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
|
||||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
||||||
assert.equal(getFromLocal("testkey3"), "testvalue3");
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||||
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
assert.equal(getFromLocal("testkey3"), "testvalue3");
|
||||||
|
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
||||||
saveToLocal("testkey6", "testvalue5");
|
|
||||||
assert.equal(getFromLocal("testkey6"), "testvalue5");
|
saveToLocal("testkey6", "testvalue5");
|
||||||
});
|
assert.equal(getFromLocal("testkey6"), "testvalue5");
|
||||||
|
});
|
||||||
it("test window locality", () => {
|
|
||||||
assert.equal(getFromLocal("testkey1"), null);
|
it("test window locality", () => {
|
||||||
assert.equal(getFromLocal("testkey2"), null);
|
assert.equal(getFromLocal("testkey1"), null);
|
||||||
assert.equal(getFromLocal("testkey3"), null);
|
assert.equal(getFromLocal("testkey2"), null);
|
||||||
assert.equal(getFromLocal("testkey4"), null);
|
assert.equal(getFromLocal("testkey3"), null);
|
||||||
});
|
assert.equal(getFromLocal("testkey4"), null);
|
||||||
|
});
|
||||||
it("test delete and fetch", () => {
|
|
||||||
saveToLocal("testkey1", "testvalue1");
|
it("test delete and fetch", () => {
|
||||||
saveToLocal("testkey2", "testvalue2");
|
saveToLocal("testkey1", "testvalue1");
|
||||||
saveToLocal("testkey3", "testvalue3");
|
saveToLocal("testkey2", "testvalue2");
|
||||||
saveToLocal("testkey4", "testvalue4");
|
saveToLocal("testkey3", "testvalue3");
|
||||||
|
saveToLocal("testkey4", "testvalue4");
|
||||||
removeFromLocal("testkey3");
|
|
||||||
|
removeFromLocal("testkey3");
|
||||||
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
|
||||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
||||||
assert.equal(getFromLocal("testkey3"), null);
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||||
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
assert.equal(getFromLocal("testkey3"), null);
|
||||||
|
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
||||||
removeFromLocal("testkey1");
|
|
||||||
|
removeFromLocal("testkey1");
|
||||||
assert.equal(getFromLocal("testkey1"), null);
|
|
||||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
assert.equal(getFromLocal("testkey1"), null);
|
||||||
assert.equal(getFromLocal("testkey3"), null);
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||||
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
assert.equal(getFromLocal("testkey3"), null);
|
||||||
|
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
||||||
removeFromLocal("testkey4");
|
|
||||||
|
removeFromLocal("testkey4");
|
||||||
assert.equal(getFromLocal("testkey1"), null);
|
|
||||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
assert.equal(getFromLocal("testkey1"), null);
|
||||||
assert.equal(getFromLocal("testkey3"), null);
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||||
assert.equal(getFromLocal("testkey4"), null);
|
assert.equal(getFromLocal("testkey3"), null);
|
||||||
|
assert.equal(getFromLocal("testkey4"), null);
|
||||||
removeFromLocal("testkey2");
|
|
||||||
|
removeFromLocal("testkey2");
|
||||||
assert.equal(getFromLocal("testkey1"), null);
|
|
||||||
assert.equal(getFromLocal("testkey2"), null);
|
assert.equal(getFromLocal("testkey1"), null);
|
||||||
assert.equal(getFromLocal("testkey3"), null);
|
assert.equal(getFromLocal("testkey2"), null);
|
||||||
assert.equal(getFromLocal("testkey4"), null);
|
assert.equal(getFromLocal("testkey3"), null);
|
||||||
});
|
assert.equal(getFromLocal("testkey4"), null);
|
||||||
|
});
|
||||||
it("test clear and fetch", () => {
|
|
||||||
saveToLocal("testkey1", "testvalue1");
|
it("test clear and fetch", () => {
|
||||||
saveToLocal("testkey2", "testvalue2");
|
saveToLocal("testkey1", "testvalue1");
|
||||||
saveToLocal("testkey3", "testvalue3");
|
saveToLocal("testkey2", "testvalue2");
|
||||||
saveToLocal("testkey4", "testvalue4");
|
saveToLocal("testkey3", "testvalue3");
|
||||||
|
saveToLocal("testkey4", "testvalue4");
|
||||||
clearLocal();
|
|
||||||
|
clearLocal();
|
||||||
assert.equal(getFromLocal("testkey1"), null);
|
|
||||||
assert.equal(getFromLocal("testkey2"), null);
|
assert.equal(getFromLocal("testkey1"), null);
|
||||||
assert.equal(getFromLocal("testkey3"), null);
|
assert.equal(getFromLocal("testkey2"), null);
|
||||||
assert.equal(getFromLocal("testkey4"), null);
|
assert.equal(getFromLocal("testkey3"), null);
|
||||||
});
|
assert.equal(getFromLocal("testkey4"), null);
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user