Skip to content

Commit

Permalink
chore: refactor all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Nov 3, 2024
1 parent 247d780 commit f75b4e0
Show file tree
Hide file tree
Showing 71 changed files with 12,177 additions and 13,110 deletions.
24,359 changes: 11,765 additions & 12,594 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/acs-client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ test/*.js
test/*.d.ts
!.eslintrc.js
!setupTopics.js
coverage/
6 changes: 0 additions & 6 deletions packages/acs-client/.mocharc.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/acs-client/cfg/config_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"logger": {
"console": {
"handleExceptions": false,
"level": "error",
"level": "silly",
"colorize": true,
"prettyPrint": true
}
}
}
}
14 changes: 3 additions & 11 deletions packages/acs-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,28 @@
"@restorecommerce/protos": "^6.8.11",
"@types/eslint__js": "^8.42.3",
"@types/koa": "^2.15.0",
"@types/mocha": "^10.0.9",
"@types/node": "^22.7.9",
"@types/redis": "^4.0.2",
"coveralls": "^3.1.1",
"cross-env": "^7.0.3",
"eslint": "^9.12.0",
"eslint-plugin-prefer-arrow-functions": "^3.4.1",
"mocha": "^10.7.3",
"nice-grpc": "^2.1.10",
"nodemon": "^3.1.7",
"npm-run-all": "^4.1.5",
"nyc": "^17.1.0",
"rimraf": "^6.0.1",
"should": "^13.2.3",
"ts-node": "^10.9.1",
"typescript": "^5.6.2",
"typescript-eslint": "8.11.0"
"typescript-eslint": "8.11.0",
"vitest": "^2.1.4"
},
"scripts": {
"build:tsc": "tsc -d",
"build:tsc:watch": "tsc -d --watch",
"build:clean": "rimraf lib",
"build": "npm-run-all lint build:clean build:tsc",
"lint": "eslint src",
"test": "npm run build && nyc npm run mocha && npm run mocha:cache",
"mocha": "cross-env NODE_ENV=test mocha --full-trace --exit --timeout 30000",
"mocha:cache": "cross-env NODE_ENV=test CACHE_ENABLED=true mocha --full-trace --exit --timeout 30000",
"test-debug": "npm run mocha -- --inspect-brk",
"lcov-report": "nyc report --reporter=lcov",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
"test": "npm run build && cross-env NODE_ENV=test vitest run && cross-env NODE_ENV=test CACHE_ENABLED=true vitest run"
},
"nx": {
"targets": {
Expand Down
21 changes: 10 additions & 11 deletions packages/acs-client/test/acs.spec.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { } from 'mocha';
import * as should from 'should';
import { accessRequest, isAllowed, whatIsAllowed } from '../lib/acs/resolver';
import { flushCache, initializeCache } from '../lib/acs/cache';
import { accessRequest, isAllowed, whatIsAllowed } from '../src/acs/resolver';
import { flushCache, initializeCache } from '../src/acs/cache';
import {
AuthZAction,
DecisionResponse,
Expand All @@ -10,17 +9,18 @@ import {
ACSClientContext,
CtxResource,
RuleRQ,
} from '../lib/acs/interfaces';
import { initAuthZ, ACSAuthZ } from '../lib/acs/authz';
import logger from '../lib/logger';
} from '../src/acs/interfaces';
import { initAuthZ, ACSAuthZ } from '../src/acs/authz';
import logger from '../src/logger';
import * as _ from 'lodash';
import { cfg } from '../lib';
import { cfg } from '../src';
import {
Request,
Response_Decision
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control';
import { GrpcMockServer } from '@alenon/grpc-mock-server';
import { Effect } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule';
import { it, describe, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';

let authZ: ACSAuthZ;

Expand Down Expand Up @@ -320,16 +320,15 @@ const stop = async (): Promise<void> => {
};

describe('Testing acs-client', () => {
before(async function startServer(): Promise<void> {
this.timeout(60000);
beforeAll(async () => {
const cacheEnabled = process.env.CACHE_ENABLED;
if (cacheEnabled && cacheEnabled.toLowerCase() === 'true') {
await initializeCache();
}
await start();
});
}, 60000);

after(async (): Promise<void> => {
afterAll(async () => {
await stop();
const cacheEnabled = process.env.CACHE_ENABLED;
if (cacheEnabled && cacheEnabled.toLowerCase() === 'true') {
Expand Down
17 changes: 8 additions & 9 deletions packages/acs-client/test/acs_multiple_entities.spec.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { } from 'mocha';
import * as should from 'should';
import {
accessRequest,
isAllowed,
whatIsAllowed
} from '../lib/acs/resolver';
import { flushCache, initializeCache } from '../lib/acs/cache';
} from '../src/acs/resolver';
import { flushCache, initializeCache } from '../src/acs/cache';
import {
AuthZAction,
DecisionResponse,
Expand All @@ -14,8 +13,8 @@ import {
ACSClientContext,
CtxResource,
} from '../lib/acs/interfaces';
import { initAuthZ, ACSAuthZ } from '../lib/acs/authz';
import logger from '../lib/logger';
import { initAuthZ, ACSAuthZ } from '../src/acs/authz';
import logger from '../src/logger';
import * as _ from 'lodash';
import {
MultiplePolicySetRQFactory,
Expand All @@ -36,6 +35,7 @@ import {
Response_Decision
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control';
import { GrpcMockServer } from '@alenon/grpc-mock-server';
import { it, describe, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';

let authZ: ACSAuthZ;

Expand Down Expand Up @@ -167,16 +167,15 @@ const subject = {
};

describe('testing acs-client with multiple entities', () => {
before(async function startServer(): Promise<void> {
this.timeout(60000);
beforeAll(async () => {
const cacheEnabled = process.env.CACHE_ENABLED;
await start();
if (cacheEnabled?.toLowerCase() === 'true') {
await initializeCache();
}
});
}, 60000);

after(async (): Promise<void> => {
afterAll(async () => {
await stop();
const cacheEnabled = process.env.CACHE_ENABLED;
if (cacheEnabled?.toLowerCase() === 'true') {
Expand Down
2 changes: 1 addition & 1 deletion packages/acs-client/test/rules_utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Effect } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule';
import { ReverseQuery } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control';
import { RuleRQ } from '../lib';
import { RuleRQ } from '../src';
import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute';

export const permitLocationRule = {
Expand Down
3 changes: 1 addition & 2 deletions packages/acs-client/tsconfig-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../../node_modules/@restorecommerce/dev/tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"types": ["node", "jest"],
"types": ["node"],
"resolveJsonModule": true
},
"exclude": [
Expand All @@ -11,4 +11,3 @@
"doc"
]
}

2 changes: 2 additions & 0 deletions packages/acs-client/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from '../../node_modules/@restorecommerce/dev/vitest.config.js';
export default config;
13 changes: 4 additions & 9 deletions packages/cluster-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@
"recluster": "^1.0.0"
},
"devDependencies": {
"coveralls": "^3.1.1",
"is-generator": "^1.0.3",
"mocha": "^10.2.0",
"nyc": "17.1.0",
"should": "^13.2.3"
"should": "^13.2.3",
"vitest": "^2.1.4"
},
"scripts": {
"test": "nyc mocha --full-trace --exit",
"lint": "eslint *.json *.js",
"mocha": "mocha ./test/*",
"lcov-report": "nyc report --reporter=lcov",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
"test": "vitest run --dangerouslyIgnoreUnhandledErrors",
"lint": "eslint *.json *.js"
},
"engines": {
"node": ">= 10.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
const ClusterServer = require('../index');
import { it, describe } from 'vitest';

const prodOptions = {
mode: 'production'
};

describe('the cluster service', function() {
it('should be able to start a server in development mode', function(done) {
it('should be able to start a server in development mode', () => {
const cluster = new ClusterServer();
cluster.run('./test/service.js');
cluster.stop();
done();
});
it('should be able to start a server in production mode', function(done) {
it('should be able to start a server in production mode', () => {
const cluster = new ClusterServer(prodOptions);
cluster.run('./test/service.js');
cluster.stop();
done();
});
});
2 changes: 2 additions & 0 deletions packages/cluster-service/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from '../../node_modules/@restorecommerce/dev/vitest.config.js';
export default config;
12 changes: 7 additions & 5 deletions packages/dev/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fileExtensionInImportTS from 'eslint-plugin-file-extension-in-import-ts';
import tsParser from '@typescript-eslint/parser';
import { plugin as tesLintPlugin } from 'typescript-eslint';
import { fixupPluginRules } from "@eslint/compat";
import stylistic from '@stylistic/eslint-plugin';

export default [
{
Expand All @@ -29,7 +30,8 @@ export default [
'@typescript-eslint': tesLintPlugin,
'prefer-arrow-functions': fixupPluginRules(preferArrowFunctions),
'unicorn': unicorn,
'file-extension-in-import-ts': fileExtensionInImportTS
'file-extension-in-import-ts': fileExtensionInImportTS,
'@stylistic': stylistic
},
rules: {
'@typescript-eslint/adjacent-overload-signatures': 'error',
Expand All @@ -44,8 +46,8 @@ export default [
'format': ['PascalCase']
}
],
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/member-delimiter-style': [
'@stylistic/indent': ['error', 2],
'@stylistic/member-delimiter-style': [
'error',
{
'multiline': {
Expand All @@ -61,11 +63,11 @@ export default [
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-use-before-define': [2, {'functions': true, 'classes': true}],
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/semi': [
'@stylistic/semi': [
'error',
'always'
],
'@typescript-eslint/type-annotation-spacing': 'error',
'@stylistic/type-annotation-spacing': 'error',
'arrow-parens': [
'off',
'as-needed'
Expand Down
6 changes: 6 additions & 0 deletions packages/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
],
"type": "module",
"dependencies": {
"@eslint/compat": "^1.0.3",
"@stylistic/eslint-plugin": "^2.10.1",
"@typescript-eslint/eslint-plugin": "8.10.0",
"@typescript-eslint/parser": "8.10.0",
"@vitest/coverage-v8": "^2.1.4",
"eslint": "^9.12.0",
"eslint-plugin-file-extension-in-import-ts": "^2.1.0",
"eslint-plugin-prefer-arrow-functions": "^3.4.1",
"eslint-plugin-unicorn": "56.0.0",
"typescript-eslint": "8.11.0",
"vitest": "^2.1.4"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
fileParallelism: false,
testTimeout: 60000,
coverage: {
enabled: true,
provider: 'v8',
Expand Down
Loading

0 comments on commit f75b4e0

Please sign in to comment.