web_plsql 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -12,11 +12,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
12
12
  ### Fixed
13
13
 
14
14
 
15
- ## [0.4.1] - 2021-08-30
15
+ ## [0.5.0] - 2022-05-09
16
16
 
17
- ### Added
17
+ ### Changed
18
+ - Replaced mocha with jest.
19
+ - Added support for node 18.
20
+
21
+ ### Fixed
22
+ - Updated all dependencies.
23
+
24
+
25
+ ## [0.4.2] - 2022-01-17
18
26
 
19
27
  ### Changed
28
+ - node.js support starting with v16.
29
+
30
+ ### Fixed
31
+ - Updated all dependencies.
32
+
33
+
34
+ ## [0.4.1] - 2021-08-30
20
35
 
21
36
  ### Fixed
22
37
  - Updated all dependencies.
@@ -49,8 +64,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
49
64
 
50
65
  ## [0.2.0] - 2019-06-02
51
66
 
52
- ### Added
53
-
54
67
  ## [0.2.0] - 2019-06-02
55
68
 
56
69
  ### Fixed
@@ -79,6 +79,23 @@ app.use(PATH + '/:name?', webplsql(connectionPool, OPTIONS));
79
79
  // serving static files
80
80
  app.use('/static', express.static(path.join(process.cwd(), 'examples/static')));
81
81
 
82
+ // shutdown
83
+ process.on('SIGTERM', shutDown);
84
+ process.on('SIGINT', shutDown);
85
+
82
86
  // listen on port
83
87
  console.log(`Sample app is listening on http://localhost:${PORT}${PATH}`);
84
- app.listen(PORT);
88
+ const server = app.listen(PORT);
89
+
90
+ function shutDown() {
91
+ console.log('Received kill signal, shutting down gracefully');
92
+ server.close(() => {
93
+ console.log('Closed out remaining connections');
94
+ process.exit(0);
95
+ });
96
+
97
+ setTimeout(() => {
98
+ console.error('Could not close connections in time, forcefully shutting down');
99
+ process.exit(1);
100
+ }, 10000);
101
+ }
package/jest.config.js ADDED
@@ -0,0 +1,204 @@
1
+ /*
2
+ * For a detailed explanation regarding each configuration property, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ module.exports = {
7
+ // All imported modules in your tests should be mocked automatically
8
+ // automock: false,
9
+
10
+ // Stop running tests after `n` failures
11
+ // bail: 0,
12
+
13
+ // The directory where Jest should store its cached dependency information
14
+ // cacheDirectory: "/private/var/folders/2y/kvrr5nws6xz4nx9vnwjxj17w0000gn/T/jest_dx",
15
+
16
+ // Automatically clear mock calls, instances, contexts and results before every test
17
+ // clearMocks: false,
18
+
19
+ // Indicates whether the coverage information should be collected while executing the test
20
+ collectCoverage: true,
21
+
22
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
23
+ // collectCoverageFrom: undefined,
24
+ collectCoverageFrom: ['./src/**/*.{ts,js}'],
25
+
26
+ // The directory where Jest should output its coverage files
27
+ coverageDirectory: "coverage",
28
+
29
+ // An array of regexp pattern strings used to skip coverage collection
30
+ // coveragePathIgnorePatterns: [
31
+ // "/node_modules/"
32
+ // ],
33
+
34
+ // Indicates which provider should be used to instrument code for coverage
35
+ coverageProvider: "v8",
36
+
37
+ // A list of reporter names that Jest uses when writing coverage reports
38
+ // coverageReporters: [
39
+ // "json",
40
+ // "text",
41
+ // "lcov",
42
+ // "clover"
43
+ // ],
44
+
45
+ // An object that configures minimum threshold enforcement for coverage results
46
+ // coverageThreshold: undefined,
47
+
48
+ // A path to a custom dependency extractor
49
+ // dependencyExtractor: undefined,
50
+
51
+ // Make calling deprecated APIs throw helpful error messages
52
+ // errorOnDeprecated: false,
53
+
54
+ // The default configuration for fake timers
55
+ // fakeTimers: {
56
+ // "enableGlobally": false
57
+ // },
58
+
59
+ // Force coverage collection from ignored files using an array of glob patterns
60
+ // forceCoverageMatch: [],
61
+
62
+ // A path to a module which exports an async function that is triggered once before all test suites
63
+ // globalSetup: undefined,
64
+
65
+ // A path to a module which exports an async function that is triggered once after all test suites
66
+ // globalTeardown: undefined,
67
+
68
+ // A set of global variables that need to be available in all test environments
69
+ // globals: {},
70
+ globals: {
71
+ 'ts-jest': {
72
+ tsconfig: 'tsconfig.src.json',
73
+ diagnostics: true,
74
+ useESM: true,
75
+ }
76
+ },
77
+
78
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
79
+ // maxWorkers: "50%",
80
+
81
+ // An array of directory names to be searched recursively up from the requiring module's location
82
+ // moduleDirectories: [
83
+ // "node_modules"
84
+ // ],
85
+
86
+ // An array of file extensions your modules use
87
+ // moduleFileExtensions: [
88
+ // "js",
89
+ // "mjs",
90
+ // "cjs",
91
+ // "jsx",
92
+ // "ts",
93
+ // "tsx",
94
+ // "json",
95
+ // "node"
96
+ // ],
97
+
98
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
99
+ // moduleNameMapper: {},
100
+
101
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
102
+ // modulePathIgnorePatterns: [],
103
+
104
+ // Activates notifications for test results
105
+ // notify: false,
106
+
107
+ // An enum that specifies notification mode. Requires { notify: true }
108
+ // notifyMode: "failure-change",
109
+
110
+ // A preset that is used as a base for Jest's configuration
111
+ // preset: undefined,
112
+ preset: 'ts-jest',
113
+
114
+ // Run tests from one or more projects
115
+ // projects: undefined,
116
+
117
+ // Use this configuration option to add custom reporters to Jest
118
+ // reporters: undefined,
119
+
120
+ // Automatically reset mock state before every test
121
+ // resetMocks: false,
122
+
123
+ // Reset the module registry before running each individual test
124
+ // resetModules: false,
125
+
126
+ // A path to a custom resolver
127
+ // resolver: undefined,
128
+
129
+ // Automatically restore mock state and implementation before every test
130
+ // restoreMocks: false,
131
+
132
+ // The root directory that Jest should scan for tests and modules within
133
+ // rootDir: undefined,
134
+
135
+ // A list of paths to directories that Jest should use to search for files in
136
+ // roots: [
137
+ // "<rootDir>"
138
+ // ],
139
+
140
+ // Allows you to use a custom runner instead of Jest's default test runner
141
+ // runner: "jest-runner",
142
+
143
+ // The paths to modules that run some code to configure or set up the testing environment before each test
144
+ // setupFiles: [],
145
+
146
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
147
+ // setupFilesAfterEnv: [],
148
+
149
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
150
+ // slowTestThreshold: 5,
151
+
152
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
153
+ // snapshotSerializers: [],
154
+
155
+ // The test environment that will be used for testing
156
+ // testEnvironment: "jest-environment-node",
157
+
158
+ // Options that will be passed to the testEnvironment
159
+ // testEnvironmentOptions: {},
160
+
161
+ // Adds a location field to test results
162
+ // testLocationInResults: false,
163
+
164
+ // The glob patterns Jest uses to detect test files
165
+ // testMatch: [
166
+ // "**/__tests__/**/*.[jt]s?(x)",
167
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
168
+ // ],
169
+
170
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
171
+ // testPathIgnorePatterns: [
172
+ // "/node_modules/"
173
+ // ],
174
+
175
+ // The regexp pattern or array of patterns that Jest uses to detect test files
176
+ // testRegex: [],
177
+
178
+ // This option allows the use of a custom results processor
179
+ // testResultsProcessor: undefined,
180
+
181
+ // This option allows use of a custom test runner
182
+ // testRunner: "jest-circus/runner",
183
+
184
+ // A map from regular expressions to paths to transformers
185
+ // transform: undefined,
186
+
187
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
188
+ // transformIgnorePatterns: [
189
+ // "/node_modules/",
190
+ // "\\.pnp\\.[^\\/]+$"
191
+ // ],
192
+
193
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
194
+ // unmockedModulePathPatterns: undefined,
195
+
196
+ // Indicates whether each individual test should be reported during the run
197
+ // verbose: undefined,
198
+
199
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
200
+ // watchPathIgnorePatterns: [],
201
+
202
+ // Whether to use watchman for file crawling
203
+ // watchman: true,
204
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web_plsql",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "author": "Dieter Oberkofler <dieter.oberkofler@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "The Express Middleware for Oracle PL/SQL",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "homepage": "https://github.com/doberkofler/web_plsql",
22
22
  "engines": {
23
- "node": ">=10"
23
+ "node": ">=16"
24
24
  },
25
25
  "maintainers": [
26
26
  {
@@ -41,72 +41,45 @@
41
41
  "eslint": "eslint --cache --report-unused-disable-directives \"./**/*.ts\"",
42
42
  "type-check": "tsc --project ./tsconfig.json --noEmit",
43
43
  "lint": "npm run eslint && npm run type-check",
44
- "test": "mocha --project ./tsconfig.test.json --require ts-node/register --require source-map-support/register --check-leaks --full-trace --bail ./test/*.ts",
45
- "test-cov": "npm run build && nyc mocha --project ./tsconfig.test.json --require ts-node/register --require source-map-support/register --check-leaks --full-trace --bail ./test/*.ts",
46
- "coveralls": "npm run test-cov && cat ./coverage/lcov.info | coveralls",
44
+ "test": "jest --coverage=false",
45
+ "test:coverage": "jest",
47
46
  "sample": "node examples/sample.js",
48
47
  "rebuild": "npm run clean && npm run lint && npm run build && npm run test",
49
48
  "create-package": "shx rm -f *.tgz && npm pack",
50
49
  "install": "npm run build"
51
50
  },
52
- "nyc": {
53
- "include": [
54
- "src/*.ts"
55
- ],
56
- "extension": [
57
- ".ts"
58
- ],
59
- "require": [
60
- "ts-node/register"
61
- ],
62
- "reporter": [
63
- "text-summary",
64
- "html"
65
- ],
66
- "sourceMap": true,
67
- "instrument": true,
68
- "all": true
69
- },
70
51
  "dependencies": {
71
- "body-parser": "1.19.0",
52
+ "body-parser": "1.20.0",
72
53
  "compression": "1.7.4",
73
54
  "connect-multiparty": "2.2.0",
74
- "cookie-parser": "1.4.5",
55
+ "cookie-parser": "1.4.6",
75
56
  "escape-html": "1.0.3",
76
- "express": "4.17.1",
77
- "express-status-monitor": "1.3.3",
78
- "http-parser-js": "0.5.3",
57
+ "express": "4.18.1",
58
+ "express-status-monitor": "1.3.4",
59
+ "http-parser-js": "0.5.6",
79
60
  "mkdirp": "1.0.4",
80
- "morgan": "1.10.0"
61
+ "morgan": "1.10.0",
62
+ "oracledb": "5.3.0"
81
63
  },
82
64
  "devDependencies": {
83
- "@types/body-parser": "1.19.1",
84
- "@types/chai": "4.2.21",
85
- "@types/compression": "1.7.1",
86
- "@types/cookie-parser": "1.4.2",
87
- "@types/escape-html": "1.0.1",
65
+ "@types/body-parser": "1.19.2",
66
+ "@types/compression": "1.7.2",
67
+ "@types/cookie-parser": "1.4.3",
68
+ "@types/escape-html": "1.0.2",
88
69
  "@types/mkdirp": "1.0.2",
89
- "@types/mocha": "9.0.0",
90
70
  "@types/morgan": "1.9.3",
91
- "@types/node": "16.7.6",
92
- "@types/oracledb": "5.2.1",
93
- "@types/supertest": "2.0.11",
94
- "@typescript-eslint/eslint-plugin": "4.29.3",
95
- "@typescript-eslint/parser": "4.29.3",
96
- "chai": "4.3.4",
97
- "coveralls": "3.1.1",
98
- "eslint": "7.32.0",
99
- "istanbul": "1.1.0-alpha.1",
100
- "mocha": "9.1.1",
101
- "nyc": "15.1.0",
71
+ "@types/node": "17.0.31",
72
+ "@types/oracledb": "5.2.3",
73
+ "@types/supertest": "2.0.12",
74
+ "@typescript-eslint/eslint-plugin": "5.22.0",
75
+ "@typescript-eslint/parser": "5.22.0",
76
+ "eslint": "8.15.0",
77
+ "jest": "28.1.0",
102
78
  "rimraf": "3.0.2",
103
- "shx": "0.3.3",
104
- "source-map-support": "0.5.19",
105
- "supertest": "6.1.6",
106
- "ts-node": "10.2.0",
107
- "typescript": "4.4.2"
108
- },
109
- "optionalDependencies": {
110
- "oracledb": "5.2.0"
79
+ "shx": "0.3.4",
80
+ "supertest": "6.2.3",
81
+ "ts-jest": "28.0.2",
82
+ "ts-node": "10.7.0",
83
+ "typescript": "4.6.4"
111
84
  }
112
85
  }
package/src/cgi.ts CHANGED
@@ -26,7 +26,7 @@ export function getCGI(req: express.Request, options: oracleExpressMiddleware$op
26
26
  'GATEWAY_IVERSION': '2',
27
27
  'SERVER_SOFTWARE': 'web_plsql',
28
28
  'GATEWAY_INTERFACE': 'CGI/1.1',
29
- 'SERVER_PORT': req.socket.localPort.toString(),
29
+ 'SERVER_PORT': typeof req.socket.localPort === 'number' ? req.socket.localPort.toString() : '',
30
30
  'SERVER_NAME': os.hostname(),
31
31
  'REQUEST_METHOD': req.method,
32
32
  'PATH_INFO': req.params.name,
package/src/errorPage.ts CHANGED
@@ -21,7 +21,7 @@ type outputType = {html: string; text: string};
21
21
  * @param {Trace} trace - Tracing object.
22
22
  * @param {Error} error - The error.
23
23
  */
24
- export function errorPage(req: express.Request, res: express.Response, options: oracleExpressMiddleware$options, trace: Trace, error: any): void { // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
24
+ export function errorPage(req: express.Request, res: express.Response, options: oracleExpressMiddleware$options, trace: Trace, error: unknown): void {
25
25
  let output = {
26
26
  html: '',
27
27
  text: ''
@@ -61,7 +61,7 @@ export function errorPage(req: express.Request, res: express.Response, options:
61
61
  /*
62
62
  * Show an error page
63
63
  */
64
- function getError(req: express.Request, error: Error): outputType {
64
+ function getError(req: express.Request, error: unknown): outputType {
65
65
  let timestamp: Date = new Date();
66
66
  let message: string = '';
67
67
  let environment: environmentType | null = null;
@@ -8,9 +8,9 @@ export class ProcedureError extends Error {
8
8
  timestamp: Date;
9
9
  environment: environmentType;
10
10
  sql: string;
11
- bind: any;
11
+ bind: unknown;
12
12
 
13
- constructor(message: string, environment: environmentType, sql: string, bind: any) { // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
13
+ constructor(message: string, environment: environmentType, sql: string, bind: unknown) {
14
14
  super(message);
15
15
 
16
16
  // Maintains proper stack trace for where our error was thrown (only available on V8)
@@ -1,8 +1,8 @@
1
- import {assert} from 'chai';
2
- import {getCGI} from '../src/cgi';
1
+ import {describe, it, expect} from '@jest/globals';
2
+ import {getCGI} from '../../src/cgi';
3
3
  import express from 'express';
4
4
  import os from 'os';
5
- import type {oracleExpressMiddleware$options} from '../src/config';
5
+ import type {oracleExpressMiddleware$options} from '../../src/config';
6
6
 
7
7
  describe('cgi', () => {
8
8
  it('with a proper configuration object and request', () => {
@@ -59,9 +59,9 @@ describe('cgi', () => {
59
59
 
60
60
  const cgi = getCGI(req as unknown as express.Request, options as unknown as oracleExpressMiddleware$options);
61
61
 
62
- assert.strictEqual(Object.keys(cgi).length, 29);
62
+ expect(Object.keys(cgi)).toHaveLength(29);
63
63
 
64
- assert.deepEqual(cgi, {
64
+ expect(cgi).toStrictEqual({
65
65
  'PLSQL_GATEWAY': 'WebDb',
66
66
  'GATEWAY_IVERSION': '2',
67
67
  'SERVER_SOFTWARE': 'web_plsql',
@@ -1,5 +1,5 @@
1
- import {assert} from 'chai';
2
- import {validate} from '../src/config';
1
+ import {describe, it, expect} from '@jest/globals';
2
+ import {validate} from '../../src/config';
3
3
 
4
4
  describe('configuration options', () => {
5
5
  it('should allow the following options', () => {
@@ -10,7 +10,7 @@ describe('configuration options', () => {
10
10
  {pathAlias: {alias: 'r', procedure: 'p'}},
11
11
  {errorStyle: 'debug'}
12
12
  ].forEach(options => {
13
- assert.strictEqual(typeof validate(options as unknown as Record<string, unknown>), 'object', JSON.stringify(options));
13
+ expect(typeof validate(options as unknown as Record<string, unknown>)).toBe('object');
14
14
  });
15
15
  });
16
16
  });
@@ -33,9 +33,9 @@ describe('configuration errors', () => {
33
33
  {config: {trace: 'enabled'}, error: 'The optional option "trace" must be "on" or "off"'},
34
34
  ].forEach(test => {
35
35
  it(`should throw the exception "${test.error}"`, () => {
36
- assert.throws(() => {
36
+ expect(() => {
37
37
  validate(test.config as unknown as Record<string, unknown>);
38
- }, test.error);
38
+ }).toThrow(test.error);
39
39
  });
40
40
  });
41
41
  });
@@ -0,0 +1,101 @@
1
+ import {describe, beforeAll, afterAll, it, expect} from '@jest/globals';
2
+ import {errorPage} from '../../src/errorPage';
3
+ import {RequestError} from '../../src/requestError';
4
+ import {ProcedureError} from '../../src/procedureError';
5
+ import {oracleExpressMiddleware$options} from '../../src/config';
6
+
7
+ describe('errorPage', () => {
8
+ let errorSave: any;
9
+
10
+ beforeAll(() => {
11
+ errorSave = console.error;
12
+ console.error = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
13
+ });
14
+
15
+ afterAll(() => {
16
+ console.error = errorSave;
17
+ });
18
+
19
+ let errorText = '';
20
+ let errorHtml = '';
21
+
22
+ const options: oracleExpressMiddleware$options = {
23
+ errorStyle: 'debug',
24
+ trace: 'off'
25
+ };
26
+
27
+ const req: any = {};
28
+ const res: any = {
29
+ status() {
30
+ return this;
31
+ },
32
+ send(error: string) {
33
+ errorHtml = error;
34
+ return this;
35
+ }
36
+ };
37
+ const trace: any = {
38
+ write(error: string) {
39
+ errorText = error;
40
+ }
41
+ };
42
+
43
+ it('should report a "error message" in text and html format', () => {
44
+ errorPage(req, res, options, trace, new Error('error message'));
45
+
46
+ expect(/error message/.test(errorText)).toBeTruthy();
47
+ expect(/ERROR/.test(errorText)).toBeTruthy();
48
+ expect(/REQUEST/.test(errorText)).toBeTruthy();
49
+ expect(/error message/.test(errorHtml)).toBeTruthy();
50
+ expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
51
+ expect(/ERROR/.test(errorHtml)).toBeTruthy();
52
+ });
53
+
54
+ it('should report a "Error" in text and html format', () => {
55
+ errorPage(req, res, options, trace, new Error('throw Error'));
56
+
57
+ expect(/throw Error/.test(errorText)).toBeTruthy();
58
+ expect(/ERROR/.test(errorText)).toBeTruthy();
59
+ expect(/REQUEST/.test(errorText)).toBeTruthy();
60
+ expect(/throw Error/.test(errorHtml)).toBeTruthy();
61
+ expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
62
+ expect(/ERROR/.test(errorHtml)).toBeTruthy();
63
+ });
64
+
65
+ it('should report a "RequestError" in text and html format', () => {
66
+ errorPage(req, res, options, trace, new RequestError('throw RequestError'));
67
+
68
+ expect(/throw RequestError/.test(errorText)).toBeTruthy();
69
+ expect(/ERROR/.test(errorText)).toBeTruthy();
70
+ expect(/REQUEST/.test(errorText)).toBeTruthy();
71
+ expect(/throw RequestError/.test(errorHtml)).toBeTruthy();
72
+ expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
73
+ expect(/ERROR/.test(errorHtml)).toBeTruthy();
74
+ });
75
+
76
+ it('should report a "ProcedureError" in text and html format', () => {
77
+ const environment = {dad: 'dad'};
78
+ const sql = 'sql';
79
+ const bind = {p1: '1'};
80
+
81
+ errorPage(req, res, options, trace, new ProcedureError('throw ProcedureError', environment, sql, bind));
82
+
83
+ expect(/throw ProcedureError/.test(errorText)).toBeTruthy();
84
+ expect(/ERROR/.test(errorText)).toBeTruthy();
85
+ expect(/REQUEST/.test(errorText)).toBeTruthy();
86
+ expect(/PROCEDURE/.test(errorText)).toBeTruthy();
87
+ expect(/ENVIRONMENT/.test(errorText)).toBeTruthy();
88
+ expect(/throw ProcedureError/.test(errorHtml)).toBeTruthy();
89
+ expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
90
+ expect(/ERROR/.test(errorHtml)).toBeTruthy();
91
+ expect(/PROCEDURE/.test(errorHtml)).toBeTruthy();
92
+ expect(/ENVIRONMENT/.test(errorHtml)).toBeTruthy();
93
+ });
94
+
95
+ it('should only report a "404" error when in basic mode', () => {
96
+ options.errorStyle = 'basic';
97
+ errorPage(req, res, options, trace, new Error('error message'));
98
+
99
+ expect(/error message/.test(errorText)).toBeTruthy();
100
+ });
101
+ });
@@ -1,16 +1,16 @@
1
- import {assert} from 'chai';
2
- import {setExecuteCallback, createPool, Connection, getConnection, ConnectionPool, Lob, BLOB} from './mock/oracledb';
1
+ import {describe, beforeEach, it, expect} from '@jest/globals';
2
+ import {setExecuteCallback, createPool, Connection, getConnection, ConnectionPool, Lob, BLOB} from '../mock/oracledb';
3
3
 
4
4
  describe('oracledb', () => {
5
5
  it('createPool', async () => {
6
6
  const connectionPool = await _createPool();
7
- assert.isTrue(connectionPool instanceof ConnectionPool);
7
+ expect(connectionPool).toBeInstanceOf(ConnectionPool);
8
8
  return connectionPool;
9
9
  });
10
10
 
11
11
  it('getConnection', async () => {
12
12
  const connection = await _getConnection();
13
- assert.isTrue(connection instanceof Connection);
13
+ expect(connection).toBeInstanceOf(Connection);
14
14
  return connection;
15
15
  });
16
16
  });
@@ -20,7 +20,7 @@ describe('ConnectionPool', () => {
20
20
  const connectionPool = await _createPool();
21
21
  const connection = await connectionPool.getConnection();
22
22
 
23
- assert.isTrue(connection instanceof Connection);
23
+ expect(connection).toBeInstanceOf(Connection);
24
24
 
25
25
  return connection;
26
26
  });
@@ -34,14 +34,14 @@ describe('ConnectionPool', () => {
34
34
  describe('Connection', () => {
35
35
  it('getConnection', async () => {
36
36
  const connection = await _getConnection();
37
- assert.isTrue(connection instanceof Connection);
37
+ expect(connection).toBeInstanceOf(Connection);
38
38
  return connection;
39
39
  });
40
40
 
41
41
  it('createLob', async () => {
42
42
  const connection = await _getConnection();
43
43
  const lob = await connection.createLob(BLOB);
44
- assert.isTrue(lob instanceof Lob);
44
+ expect(lob).toBeInstanceOf(Lob);
45
45
  return lob;
46
46
  });
47
47
 
@@ -58,7 +58,7 @@ describe('Connection.execute', () => {
58
58
 
59
59
  it('execute', async () => {
60
60
  const connection = await _getConnection();
61
- assert.deepEqual(await connection.execute('select * from dual'), {});
61
+ expect(await connection.execute('select * from dual')).toStrictEqual({});
62
62
  });
63
63
 
64
64
  it('execute with execution callback', async () => {
@@ -67,11 +67,11 @@ describe('Connection.execute', () => {
67
67
 
68
68
  // register an execute callback
69
69
  setExecuteCallback((sql: string) => {
70
- assert.strictEqual(sql, SQL);
70
+ expect(sql).toBe(SQL);
71
71
  return {sql: SQL};
72
72
  });
73
73
 
74
- assert.deepEqual(await connection.execute(SQL), {sql: SQL});
74
+ expect(await connection.execute(SQL)).toStrictEqual({sql: SQL});
75
75
  });
76
76
  });
77
77
 
@@ -1,4 +1,4 @@
1
- import {assert} from 'chai';
1
+ import {describe, beforeAll, afterAll, beforeEach, it, expect} from '@jest/globals';
2
2
  import util from 'util';
3
3
  import express from 'express';
4
4
  import http from 'http';
@@ -10,9 +10,9 @@ import multipart from 'connect-multiparty';
10
10
  import cookieParser from 'cookie-parser';
11
11
  import compression from 'compression';
12
12
  import request from 'supertest';
13
- import {setExecuteCallback, createPool} from './mock/oracledb';
13
+ import {setExecuteCallback, createPool} from '../mock/oracledb';
14
14
 
15
- const webplsql = require('../src/index'); // eslint-disable-line @typescript-eslint/no-var-requires
15
+ const webplsql = require('../../src/index'); // eslint-disable-line @typescript-eslint/no-var-requires
16
16
 
17
17
  const PORT = 8765;
18
18
  const PATH = '/base';
@@ -29,10 +29,10 @@ describe('server utilities', () => {
29
29
  it('should start a server', async () => {
30
30
  const serverConfig = await serverStart();
31
31
 
32
- assert.strictEqual(Object.prototype.toString.call(serverConfig), '[object Object]');
33
- assert.strictEqual(Object.prototype.toString.call(serverConfig.app.listen), '[object Function]');
34
- assert.strictEqual(Object.prototype.toString.call(serverConfig.server), '[object Object]');
35
- //assert.isTrue(serverConfig.connectionPool instanceof oracledb.Pool);
32
+ expect(Object.prototype.toString.call(serverConfig)).toBe('[object Object]');
33
+ expect(Object.prototype.toString.call(serverConfig.app.listen)).toBe('[object Function]');
34
+ expect(Object.prototype.toString.call(serverConfig.server)).toBe('[object Object]');
35
+ //expect(serverConfig.connectionPool).toBeInstanceOf(oracledb.Pool);
36
36
 
37
37
  await serverStop(serverConfig);
38
38
  });
@@ -41,15 +41,15 @@ describe('server utilities', () => {
41
41
  describe('server static', () => {
42
42
  let serverConfig: any;
43
43
 
44
- before('Start the server', async () => {
44
+ beforeAll(async () => {
45
45
  serverConfig = await serverStart();
46
46
  });
47
47
 
48
- after('Stop the server', async () => {
48
+ afterAll(async () => {
49
49
  await serverStop(serverConfig);
50
50
  });
51
51
 
52
- beforeEach('Reset the execute callback', () => {
52
+ beforeEach(() => {
53
53
  setExecuteCallback();
54
54
  });
55
55
 
@@ -1,5 +1,5 @@
1
- import {assert} from 'chai';
2
- import {streamToBuffer} from '../src/stream';
1
+ import {describe, it, expect} from '@jest/globals';
2
+ import {streamToBuffer} from '../../src/stream';
3
3
  import fs from 'fs';
4
4
 
5
5
  describe('stream', () => {
@@ -14,7 +14,7 @@ describe('stream', () => {
14
14
  const readStream = fs.createReadStream('file.tmp');
15
15
  const readBuffer = await streamToBuffer(readStream);
16
16
 
17
- assert.isTrue(buffer.equals(readBuffer));
17
+ expect(buffer.equals(readBuffer)).toBeTruthy();
18
18
 
19
19
  fs.unlinkSync(filename);
20
20
  });
package/test/errorPage.ts DELETED
@@ -1,101 +0,0 @@
1
- import {assert} from 'chai';
2
- import {errorPage} from '../src/errorPage';
3
- import {RequestError} from '../src/requestError';
4
- import {ProcedureError} from '../src/procedureError';
5
- import {oracleExpressMiddleware$options} from '../src/config';
6
-
7
- describe('errorPage', () => {
8
- let errorSave: any;
9
-
10
- before(() => {
11
- errorSave = console.error;
12
- console.error = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
13
- });
14
-
15
- after(() => {
16
- console.error = errorSave;
17
- });
18
-
19
- let errorText = '';
20
- let errorHtml = '';
21
-
22
- const options: oracleExpressMiddleware$options = {
23
- errorStyle: 'debug',
24
- trace: 'off'
25
- };
26
-
27
- const req: any = {};
28
- const res: any = {
29
- status() {
30
- return this;
31
- },
32
- send(error: string) {
33
- errorHtml = error;
34
- return this;
35
- }
36
- };
37
- const trace: any = {
38
- write(error: string) {
39
- errorText = error;
40
- }
41
- };
42
-
43
- it('should report a "error message" in text and html format', () => {
44
- errorPage(req, res, options, trace, new Error('error message'));
45
-
46
- assert.isTrue(/error message/.test(errorText), 'text: error message');
47
- assert.isTrue(/ERROR/.test(errorText), 'text: ERROR');
48
- assert.isTrue(/REQUEST/.test(errorText), 'text: REQUEST');
49
- assert.isTrue(/error message/.test(errorHtml), 'html: error message');
50
- assert.isTrue(/TIMESTAMP/.test(errorHtml), 'html: TIMESTAMP');
51
- assert.isTrue(/ERROR/.test(errorHtml), 'html: ERROR');
52
- });
53
-
54
- it('should report a "Error" in text and html format', () => {
55
- errorPage(req, res, options, trace, new Error('throw Error'));
56
-
57
- assert.isTrue(/throw Error/.test(errorText), 'text: exception message');
58
- assert.isTrue(/ERROR/.test(errorText), 'text: ERROR');
59
- assert.isTrue(/REQUEST/.test(errorText), 'text: REQUEST');
60
- assert.isTrue(/throw Error/.test(errorHtml), 'html: exception message');
61
- assert.isTrue(/TIMESTAMP/.test(errorHtml), 'html: TIMESTAMP');
62
- assert.isTrue(/ERROR/.test(errorHtml), 'html: ERROR');
63
- });
64
-
65
- it('should report a "RequestError" in text and html format', () => {
66
- errorPage(req, res, options, trace, new RequestError('throw RequestError'));
67
-
68
- assert.isTrue(/throw RequestError/.test(errorText), 'text: exception message');
69
- assert.isTrue(/ERROR/.test(errorText), 'text: ERROR');
70
- assert.isTrue(/REQUEST/.test(errorText), 'text: REQUEST');
71
- assert.isTrue(/throw RequestError/.test(errorHtml), 'html: exception message');
72
- assert.isTrue(/TIMESTAMP/.test(errorHtml), 'html: TIMESTAMP');
73
- assert.isTrue(/ERROR/.test(errorHtml), 'html: ERROR');
74
- });
75
-
76
- it('should report a "ProcedureError" in text and html format', () => {
77
- const environment = {dad: 'dad'};
78
- const sql = 'sql';
79
- const bind = {p1: '1'};
80
-
81
- errorPage(req, res, options, trace, new ProcedureError('throw ProcedureError', environment, sql, bind));
82
-
83
- assert.isTrue(/throw ProcedureError/.test(errorText), 'text: exception message');
84
- assert.isTrue(/ERROR/.test(errorText), 'text: ERROR');
85
- assert.isTrue(/REQUEST/.test(errorText), 'text: REQUEST');
86
- assert.isTrue(/PROCEDURE/.test(errorText), 'text: PROCEDURE');
87
- assert.isTrue(/ENVIRONMENT/.test(errorText), 'text: ENVIRONMENT');
88
- assert.isTrue(/throw ProcedureError/.test(errorHtml), 'html: exception message');
89
- assert.isTrue(/TIMESTAMP/.test(errorHtml), 'html: TIMESTAMP');
90
- assert.isTrue(/ERROR/.test(errorHtml), 'html: ERROR');
91
- assert.isTrue(/PROCEDURE/.test(errorHtml), 'html: REQUEST');
92
- assert.isTrue(/ENVIRONMENT/.test(errorHtml), 'text: ENVIRONMENT');
93
- });
94
-
95
- it('should only report a "404" error when in basic mode', () => {
96
- options.errorStyle = 'basic';
97
- errorPage(req, res, options, trace, new Error('error message'));
98
-
99
- assert.isTrue(/error message/.test(errorText), 'Page not found');
100
- });
101
- });
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "skipLibCheck": true,
4
- "moduleResolution": "node",
5
- "baseUrl": ".",
6
- "outDir": "lib",
7
- "target": "es6",
8
- "lib": [
9
- "es2015",
10
- "es2016",
11
- "es2017",
12
- "es2018"
13
- ],
14
- "module": "commonjs",
15
- "sourceMap": true,
16
- "strict": true,
17
- "alwaysStrict": true,
18
- "esModuleInterop": true
19
- }
20
- }