Skip to content

Commit

Permalink
šŸšš Move tests around a bit (#110)
Browse files Browse the repository at this point in the history
- Move mocha tests from `tdf3/tests` to `tests/mocha`
- Move web-test-runner tests from `test` into `tests/web`
- Deletes a bunch of defunct and unused tests
- Updates a few tests to be written in typescript. a few JS ones remain, though
- Somehow there are some lint errors now? I fixed them
- Why? This prevents accidentally including test, fixture, or mock code in the built artifacts, simplifies coverage and test configurations by reducing the number of 'excludes' we have to add, and otherwise gets us closer to a simpler layout
  • Loading branch information
dmihalcik-virtru authored Nov 28, 2022
1 parent f0df19c commit fedb94b
Show file tree
Hide file tree
Showing 104 changed files with 2,202 additions and 2,998 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ dist
# TernJS port file
.tern-port
/.idea/

# temporary folders
**/temp/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ clean:
rm -rf */node_modules

ci: lib/opentdf-client-$(version).tgz
for x in cli web-app; do (cd $$x && npm uninstall @opentdf/client && npm ci && npm i ../lib/opentdf-client-$(version).tgz) || exit 1; done
for x in cli cli-commonjs web-app; do (cd $$x && npm uninstall @opentdf/client && npm ci && npm i ../lib/opentdf-client-$(version).tgz) || exit 1; done

i:
(cd lib && npm i && npm pack)
Expand Down
2,023 changes: 1,042 additions & 981 deletions cli/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"prepack": "npm run build",
"test": "npm run build && mocha dist/**/*.spec.js",
"watch": "(trap 'kill 0' SIGINT; npm run build && (npm run build:watch & npm run test -- --watch))",
"format": "prettier --write \"{src,test}/**/*.ts\"",
"format": "prettier --write \"{src,tests}/**/*.ts\"",
"license-check": "license-checker --production --onlyAllow 'Apache-2.0; BSD; CC-BY-4.0; ISC; MIT'",
"lint": "eslint ./{src,test}/**/*.ts"
"lint": "eslint ./{src,tests}/**/*.ts"
},
"bin": {
"opentdf": "./bin/opentdf.mjs"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"target": "es2020",
"typeRoots": ["./node_modules/@types"],
},
"include": ["src", "test", "types"],
"include": ["src", "tests", "types"],
"exclude": ["**/node_modules"]
}
1 change: 0 additions & 1 deletion lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ env:
browser: true
rules:
"@typescript-eslint/ban-ts-comment": off
strict: off
extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
Expand Down
4 changes: 2 additions & 2 deletions lib/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extension": ["ts"],
"spec": ["tdf3/test/**/*.spec.+(js|ts)"],
"require": "tdf3/test/babel-register.js"
"spec": ["tests/mocha/**/*.spec.+(js|ts)"],
"require": "tests/mocha/babel-register.js"
}
2 changes: 1 addition & 1 deletion lib/.nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"tdf3/src/**/*.ts"
],
"exclude": [
"tdf3/test/**/*.spec.*"
"tests/mocha/**/*.spec.*"
],
"require": [
"ts-node/register"
Expand Down
6 changes: 3 additions & 3 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
"build": "npm run clean && webpack && tsc -p tsconfig-esm.json && node prepareNodeESM.js && ../scripts/add-module-types.sh esm && ../scripts/fill-version.sh",
"clean": "rm -rf {build,dist}",
"doc": "typedoc --out dist/docs src/index.ts",
"format": "prettier --write \"{src,tdf3,test}/**/*.ts\"",
"format": "prettier --write \"{src,tdf3,tests}/**/*.ts\"",
"license-check": "license-checker --production --onlyAllow 'Apache-2.0; BSD; CC-BY-4.0; ISC; MIT'",
"lint": "eslint ./{src,test}/**/*.ts",
"lint": "eslint ./{src,tdf3,tests}/**/*.ts",
"prepack": "npm run build",
"test": "npm run clean && tsc -p tsconfig-esm.json && web-test-runner && npm run test:tdf3",
"test:watch": "web-test-runner --watch",
"test:tdf3": "c8 mocha --file tdf3/test/setup.js --require @babel/register --timeout 300000",
"test:tdf3": "c8 mocha --file tests/mocha/setup.js --require @babel/register --timeout 300000",
"watch": "(trap 'kill 0' SIGINT; npm run build && (npm run build:watch & npm run test -- --watch))"
},
"dependencies": {
Expand Down
12 changes: 0 additions & 12 deletions lib/tdf3/.gitignore

This file was deleted.

6 changes: 3 additions & 3 deletions lib/tdf3/src/crypto/crypto-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @param size in bits requested
* @param minSize in bits allowed
*/
export const isValidAsymmetricKeySize = (size: number | undefined, minSize: number): boolean => {
export const isValidAsymmetricKeySize = (size: number | undefined, minSize?: number): boolean => {
// No size specified is fine because the minSize will be used
if (size === undefined) {
return true;
return !!minSize;
}

if (typeof size !== 'number' || size < minSize) {
if (typeof size !== 'number' || (minSize && size < minSize)) {
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/tdf3/src/tdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ class TDF extends EventEmitter {
* @param {String} transferUrl
* @return {Buffer}
*/
static wrapHtml(payload: Buffer, manifest: Manifest, transferUrl: string): Buffer {
static wrapHtml(payload: Buffer, manifest: Manifest | string, transferUrl: string): Buffer {
const { origin } = new URL(transferUrl);
const exportManifest: string = JSON.stringify(manifest);
const exportManifest: string =
typeof manifest === 'string' ? manifest : JSON.stringify(manifest);

const fullHtmlString = htmlWrapperTemplate({
transferUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export async function* getDataReadableStream(data: ReadableStream): AsyncGenerat
// Else yield the chunk.
yield Buffer.from(value);
}
} catch (e) {
throw e;
} finally {
// release the lock for reading from this stream.
reader.releaseLock();
Expand Down
1 change: 1 addition & 0 deletions lib/tdf3/src/utils/aws-lib-storage/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
* @internal
*/
export const ClientSharedValues = {
// eslint-disable-next-line @typescript-eslint/no-empty-function
lstatSync: () => {},
};
12 changes: 0 additions & 12 deletions lib/tdf3/test/__fixtures__/hs256.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
24 changes: 0 additions & 24 deletions lib/tdf3/test/unit/mock-stream.spec.js

This file was deleted.

10 changes: 0 additions & 10 deletions lib/test/nanotdf/browser-tests/client.test-browser.js

This file was deleted.

88 changes: 0 additions & 88 deletions lib/test/nanotdf/browser-tests/fixtures.js

This file was deleted.

34 changes: 0 additions & 34 deletions lib/test/nanotdf/browser-tests/helpers.js

This file was deleted.

47 changes: 0 additions & 47 deletions lib/test/nanotdf/browser-tests/index.html

This file was deleted.

Loading

0 comments on commit fedb94b

Please sign in to comment.