Skip to content

Commit

Permalink
fix the tests, remove code coverage
Browse files Browse the repository at this point in the history
mv3 makes code cov w/ istanbul virtually impossible due to restrictions on unsafe-eval
  • Loading branch information
mymindstorm committed Mar 15, 2024
1 parent 7f1368c commit 013904a
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 298 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Setup Node.js environment
uses: actions/[email protected]

- name: Install dependencies
run: |
npm i prettier
Expand All @@ -23,20 +23,20 @@ jobs:
build:
runs-on: ubuntu-latest
name: Build ${{ matrix.platform }}

strategy:
matrix:
platform: ["chrome", "firefox"]

steps:
- uses: actions/checkout@v2

- name: Setup Node.js environment
uses: actions/[email protected]

- name: Install dependencies
run: npm ci

- name: Build
run: npm run ${{ matrix.platform }}
run-tests:
Expand All @@ -59,6 +59,3 @@ jobs:
uses: mujo-code/puppeteer-headful@master
with:
args: npm test

- name: Codecov
uses: codecov/[email protected]
6 changes: 2 additions & 4 deletions manifests/manifest-chrome-testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
},
"sandbox": {
"pages": [
"view/argon.html",
"view/test.html"
"view/argon.html"
]
},
"permissions": [
Expand All @@ -69,8 +68,7 @@
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
],
"content_security_policy": {
"extension_pages": "script-src 'self'; font-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/; default-src 'none'",
"sandbox": "sandbox allow-scripts; script-src 'self' 'unsafe-eval';"
"extension_pages": "script-src 'self'; font-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/; default-src 'none'"
},
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjo5++7m6mlJGqKOnlYehr9tjIqahMZBJUG7PLa7dSRk6bDUu2pVodO1TQWviHlrDTLP+zfoVbDBS8v8cjloK5Tn90nzC6a957dPzOfyC1WUNYNDlGM0BCmZKVP/MWB3d0ffOmTwaxh0L47aLH5nTW0AUmuwCWCBEEl4Acuyp7rwLNGlazBpaom1Qb5ckn29gCJVVVIZ6wudmcrG/FPTNJXQbg8N6wObGrgGOaxmowbkzJmIfKTyHlYOKLAjZ7aJi0W6jsy47/aV+ojvn4gO+ka6BcRhUeWgoQxqEky119f3OWiVP46SJVbAi0pkknThUjDvX11lATGjB5EvJZGyotwIDAQAB"
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"homepage": "https://github.com/Authenticator-Extension/Authenticator#readme",
"devDependencies": {
"@jsdevtools/coverage-istanbul-loader": "^3.0.5",
"@types/argon2-browser": "^1.18.1",
"@types/chai": "^4.2.14",
"@types/chrome": "^0.0.210",
Expand Down
18 changes: 0 additions & 18 deletions scripts/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface StrippedTestResults {
declare global {
interface Window {
__mocha_test_results__: MochaTestResults;
__coverage__: any;
}
}
interface TestDisplay {
Expand All @@ -44,12 +43,6 @@ async function runTests() {
"--lang=en-US,en"
];

if (!process.env.CI) {
// run with --single-process to prevent zombie Chromium processes from not terminating during development testing
// do not use this in CI as it will not run properly
puppeteerArgs.push("--single-process");
}

const browser = await puppeteer.launch({
ignoreDefaultArgs: ["--disable-extensions"],
args: puppeteerArgs,
Expand All @@ -68,36 +61,25 @@ async function runTests() {
}

const results: {
coverage: unknown;
testResults: MochaTestResults;
} = await mochaPage.evaluate(() => {
return new Promise((resolve: (value: {
coverage: unknown;
testResults: MochaTestResults;
}) => void) => {
window.addEventListener("testsComplete", () => {
resolve({
coverage: window.__coverage__,
testResults: window.__mocha_test_results__,
});
});

if (window.__mocha_test_results__.completed) {
resolve({
coverage: window.__coverage__,
testResults: window.__mocha_test_results__,
});
}
});
});

if (process.env.CI) {
if (!fs.existsSync(".nyc_output")) fs.mkdirSync(".nyc_output");
fs.writeFileSync(".nyc_output/out.json", JSON.stringify(results.coverage));
const output = execSync("./node_modules/.bin/nyc report --reporter=text-lcov");
fs.writeFileSync("coverage.lcov", output);
}

let failedTest = false;
let display: TestDisplay = {};
if (results?.testResults.tests) {
Expand Down
11 changes: 5 additions & 6 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const userAgent = navigator.userAgent;

export const isFirefox = userAgent.indexOf("Firefox") >= 0;
export const isWebKit = userAgent.indexOf("AppleWebKit") >= 0;
export const isFirefox = navigator.userAgent.indexOf("Firefox") >= 0;
export const isWebKit = navigator.userAgent.indexOf("AppleWebKit") >= 0;
export const isEdge = navigator.userAgent.indexOf("Edg") >= 0;
export const isChromium = userAgent.indexOf("Chrome") >= 0;
export const isSafari = !isChromium && userAgent.indexOf("Safari") >= 0;
export const isChromium = navigator.userAgent.indexOf("Chrome") >= 0;
export const isSafari =
!isChromium && navigator.userAgent.indexOf("Safari") >= 0;
export const isChrome =
navigator.userAgent.indexOf("Chrome") !== -1 &&
navigator.userAgent.indexOf("Edg") === -1;
2 changes: 1 addition & 1 deletion src/components/Popup/MenuPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default Vue.extend({
openHelp() {
let url = "https://otp.ee/chromeissues";
if (isFirefox) {
if (navigator.userAgent.indexOf("Firefox") !== -1) {
url = "https://otp.ee/firefoxissues";
} else if (navigator.userAgent.indexOf("Edg") !== -1) {
url = "https://otp.ee/edgeissues";
Expand Down
6 changes: 6 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "mocha";
import { MochaReporter } from "./mochaReporter";
import sinon from "sinon";

// @ts-expect-error this is not a node require
const tests = require.context("./test", true, /\.tsx?$/);
Expand All @@ -8,6 +9,11 @@ tests.keys().forEach(tests);
mocha.setup({
// @ts-expect-error - typings are wrong
reporter: MochaReporter,
rootHooks: {
afterEach() {
sinon.restore();
},
},
});

mocha.run();
178 changes: 87 additions & 91 deletions src/test/components/Popup/EnterPasswordPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,97 +16,93 @@ mocha.setup("bdd");
const localVue = createLocalVue();

describe("EnterPasswordPage", () => {
it("Tests disabled.", async () => {
return true;
before(async () => {
localVue.prototype.i18n = await loadI18nMessages();
localVue.use(Vuex);
for (const component of CommonComponents) {
localVue.component(component.name, component.component);
}
});

// before(async () => {
// localVue.prototype.i18n = await loadI18nMessages();
// localVue.use(Vuex);
// for (const component of CommonComponents) {
// localVue.component(component.name, component.component);
// }
// });

// let storeOpts = {
// modules: {
// accounts: {
// actions: {
// applyPassphrase: sinon.fake(),
// },
// state: {
// wrongPassword: false,
// },
// namespaced: true,
// },
// },
// };
// let store: Store<typeof storeOpts>;

// beforeEach(() => {
// // TODO: find a nicer var
// storeOpts.modules.accounts.actions.applyPassphrase.resetHistory();
// store = new Vuex.Store(storeOpts);
// });

// it("should apply password when button is clicked", async () => {
// const wrapper = mount(EnterPasswordPage, { store, localVue });

// const passwordInput = wrapper.find("input");
// const passwordButton = wrapper.find("button");

// passwordInput.setValue("somePassword");
// await passwordButton.trigger("click");
// storeOpts.modules.accounts.actions.applyPassphrase.should.have.been.calledWith(
// sinon.match.any,
// "somePassword"
// );
// });

// it("should apply password when enter is pressed", async () => {
// const wrapper = mount(EnterPasswordPage, { store, localVue });

// const passwordInput = wrapper.find("input");

// passwordInput.setValue("anotherPassword");
// await passwordInput.trigger("keyup.enter");
// storeOpts.modules.accounts.actions.applyPassphrase.should.have.been.calledWith(
// sinon.match.any,
// "anotherPassword"
// );
// });

// it("should autofocus password input", () => {
// const wrapper = mount(EnterPasswordPage, {
// store,
// localVue,
// attachToDocument: true,
// });

// const passwordInput = wrapper.find("input");

// passwordInput.element.should.eq(document.activeElement);
// });

// it("should not show incorrect password message", () => {
// const wrapper = mount(EnterPasswordPage, { store, localVue });

// const errorText = wrapper.find("label.warning");

// errorText.isVisible().should.be.false;
// });

// context("Incorrect password was entered", () => {
// before(() => {
// storeOpts.modules.accounts.state.wrongPassword = true;
// });

// it("should show incorrect password message", () => {
// const wrapper = mount(EnterPasswordPage, { store, localVue });

// const errorText = wrapper.find("label.warning");

// errorText.isVisible().should.be.true;
// });
// });
let storeOpts = {
modules: {
accounts: {
actions: {
applyPassphrase: sinon.fake(),
},
state: {
wrongPassword: false,
},
namespaced: true,
},
},
};
let store: Store<typeof storeOpts>;

beforeEach(() => {
// TODO: find a nicer var
storeOpts.modules.accounts.actions.applyPassphrase.resetHistory();
store = new Vuex.Store(storeOpts);
});

it("should apply password when button is clicked", async () => {
const wrapper = mount(EnterPasswordPage, { store, localVue });

const passwordInput = wrapper.find("input");
const passwordButton = wrapper.find("button");

passwordInput.setValue("somePassword");
await passwordButton.trigger("click");
storeOpts.modules.accounts.actions.applyPassphrase.should.have.been.calledWith(
sinon.match.any,
"somePassword"
);
});

it("should apply password when enter is pressed", async () => {
const wrapper = mount(EnterPasswordPage, { store, localVue });

const passwordInput = wrapper.find("input");

passwordInput.setValue("anotherPassword");
await passwordInput.trigger("keyup.enter");
storeOpts.modules.accounts.actions.applyPassphrase.should.have.been.calledWith(
sinon.match.any,
"anotherPassword"
);
});

it("should autofocus password input", () => {
const wrapper = mount(EnterPasswordPage, {
store,
localVue,
attachToDocument: true,
});

const passwordInput = wrapper.find("input");

passwordInput.element.should.eq(document.activeElement);
});

it("should not show incorrect password message", () => {
const wrapper = mount(EnterPasswordPage, { store, localVue });

const errorText = wrapper.find("label.warning");

errorText.isVisible().should.be.false;
});

context("Incorrect password was entered", () => {
before(() => {
storeOpts.modules.accounts.state.wrongPassword = true;
});

it("should show incorrect password message", () => {
const wrapper = mount(EnterPasswordPage, { store, localVue });

const errorText = wrapper.find("label.warning");

errorText.isVisible().should.be.true;
});
});
});
Loading

0 comments on commit 013904a

Please sign in to comment.