add testing to webapp

This commit is contained in:
Maxime Cannoodt 2022-07-04 22:08:13 +02:00
parent 7dd31ce43d
commit 587a561035
8 changed files with 1656 additions and 6 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ node_modules
server/.env
*.sqlite
*.sqlite-journal
*/**/coverage

View File

@ -6,7 +6,8 @@
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"test": "vitest",
"test-watch": "vitest",
"test": "vitest run",
"coverage": "vitest run --coverage",
"version": "node version-bump.mjs && git add manifest.json versions.json"
},

View File

@ -4,7 +4,9 @@
"description": "",
"main": "server.js",
"scripts": {
"test": "vitest",
"test-watch": "vitest",
"test": "vitest run",
"coverage": "vitest run --coverage",
"build": "npx tsc",
"dev": "npx nodemon ./server.ts"
},

1608
webapp/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,10 @@
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check --plugin-search-dir=. . && eslint .",
"format": "prettier --write --plugin-search-dir=. ."
"format": "prettier --write --plugin-search-dir=. .",
"test-watch": "vitest",
"test": "vitest run",
"coverage": "vitest run --coverage"
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
@ -21,9 +24,11 @@
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"autoprefixer": "^10.4.7",
"c8": "^7.11.3",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^4.0.0",
"happy-dom": "^6.0.0",
"postcss": "^8.4.14",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",
@ -32,7 +37,9 @@
"svelte-preprocess": "^4.10.7",
"tailwindcss": "^3.1.3",
"tslib": "^2.3.1",
"typescript": "^4.7.2"
"typescript": "^4.7.2",
"vitest": "^0.17.0",
"vitest-svelte-kit": "^0.0.6"
},
"type": "module",
"dependencies": {

View File

@ -0,0 +1,25 @@
import { expect, it } from 'vitest';
import decrypt from './decrypt';
const TEST_NOTE = {
ciphertext: 'U2FsdGVkX1+r+nJffb6piMq1hPFSBSkf9/sgXj/UalA=',
hmac: '7bfd5b0e96a0ed7ea43091d3e26f7c487bcebf8ba06175a4d4fc4d8466ba37f6'
};
const TEST_KEY = 'mgyUwoFwhlb1cnjhYYSrkY9_7hZKcRHQJs5l8wYB3Vk';
const TEST_PLAINTEXT = 'You did it!';
it('Should return plaintext with the correct key', () => {
decrypt({ ...TEST_NOTE, key: TEST_KEY }).then((plaintext) => {
expect(plaintext).toContain(TEST_PLAINTEXT);
});
});
it('Should throw with the wrong key', async () => {
await expect(decrypt({ ...TEST_NOTE, key: '' })).rejects.toThrow('Failed HMAC check');
});
it('Should throw with the wrong HMAC', async () => {
await expect(decrypt({ ...TEST_NOTE, hmac: '', key: TEST_KEY })).rejects.toThrow(
'Failed HMAC check'
);
});

View File

@ -12,7 +12,12 @@ const config = {
})
],
kit: {
adapter: adapter()
adapter: adapter(),
vite: {
test: {
environment: 'happy-dom'
}
}
}
};

3
webapp/vitest.config.ts Normal file
View File

@ -0,0 +1,3 @@
import { extractFromSvelteConfig } from 'vitest-svelte-kit';
export default extractFromSvelteConfig();