diff --git a/.eslintrc b/.eslintrc index 939f4f4e2d..ed1a980811 100644 --- a/.eslintrc +++ b/.eslintrc @@ -31,7 +31,6 @@ "consistent-this": "error", "prefer-arrow-callback": "error", "prefer-const": "error", - "arrow-parens": ["error", "as-needed"], "arrow-body-style": ["error", "as-needed"], "no-var": "error", "no-use-before-define": "error", @@ -70,6 +69,18 @@ "parserOptions": { "sourceType": "module" } + }, + { + "files": ["**/**/*.test.*"], + "rules": { + "arrow-parens": ["error", "always"] + } + }, + { + "files": ["**/*.mjs"], + "parserOptions": { + "sourceType": "module" + } } ] } diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 084ac27828..85b8332bd0 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18.x] + node-version: [20.x] mysql-version: ["mysql:8.0.18"] use-compression: [0] use-tls: [0] @@ -26,22 +26,22 @@ jobs: name: Performance regression check steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # - name: Set up MySQL # run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_ROOT_PASSWORD=${{ env.MYSQL_PASSWORD }} -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/test/fixtures/custom-conf:/etc/mysql/conf.d -v $PWD/test/fixtures/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }} - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - + - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- - + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- + - name: Install npm dependencies run: npm ci @@ -68,4 +68,4 @@ jobs: alert-threshold: '150%' github-token: ${{ secrets.GITHUB_TOKEN }} comment-on-alert: true - alert-comment-cc-users: '@sidorares' \ No newline at end of file + alert-comment-cc-users: '@sidorares' diff --git a/.github/workflows/ci-bun.yml b/.github/workflows/ci-bun.yml deleted file mode 100644 index 5dddc2bc8c..0000000000 --- a/.github/workflows/ci-bun.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: CI - Linux (bun) - -# this will be merged with ci-linux.yml - -on: - pull_request: - push: - branches: [ main ] - - workflow_dispatch: - -env: - MYSQL_PORT: 3306 - MYSQL_USER: root - MYSQL_DATABASE: test - -jobs: - tests-linux: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - bun-version: [canary] - mysql-version: ["mysql:5.7", "mysql:8.0.18", "mysql:8.0.22"] - use-compression: [0, 1] - use-tls: [0,1] - include: - - bun-version: "0.6.13" - use-compression: 1 - use-tls: 0 - mysql-version: "mysql:8.0.18" - - bun-version: "0.6.13" - use-compression: 1 - use-tls: 0 - mysql-version: "mysql:8.0.22" - - name: Bun ${{ matrix.bun-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}} - - steps: - - uses: actions/checkout@v3 - - name: Set up MySQL - run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/test/fixtures/custom-conf:/etc/mysql/conf.d -v $PWD/test/fixtures/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }} - - - name: Set up Bun ${{ matrix.bun-version }} - uses: oven-sh/setup-bun@v1 - with: - bun-version: ${{ matrix.bun-version }} - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- - - - name: Install npm dependencies - run: npm ci - - # - name: Install npm dependencies - # run: bun install - - - name: Wait mysql server is ready - run: node tools/wait-up.js - - # todo: run full test suite once test createServer is implemented using Bun.listen - - name: run tests - env: - MYSQL_USER: ${{ env.MYSQL_USER }} - MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }} - MYSQL_PORT: ${{ env.MYSQL_PORT }} - MYSQL_USE_COMPRESSION: ${{ matrix.use-compression }} - MYSQL_USE_TLS: ${{ matrix.use-tls }} - run: | - bun test/integration/connection/test-select-1.js - bun test/integration/connection/test-select-ssl.js - timeout-minutes: 1 diff --git a/.github/workflows/ci-coverage.yml b/.github/workflows/ci-coverage.yml new file mode 100644 index 0000000000..7f219470dd --- /dev/null +++ b/.github/workflows/ci-coverage.yml @@ -0,0 +1,86 @@ +name: CI - Coverage + +on: + pull_request: + push: + branches: [ main ] + + workflow_dispatch: + +env: + MYSQL_PORT: 3306 + MYSQL_USER: root + MYSQL_DATABASE: test + +jobs: + coverage: + permissions: write-all + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: [20.x] + mysql-version: ["mysql:8.0.33"] + use-compression: [0] + use-tls: [0] + mysql_connection_url_key: [""] + env: + MYSQL_CONNECTION_URL: ${{ secrets[matrix.mysql_connection_url_key] }} + + name: Coverage ${{ matrix.node-version }} - DB ${{ matrix.mysql-version }}${{ matrix.mysql_connection_url_key }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}} + + steps: + - uses: actions/checkout@v4 + + - name: Delete artifacts + uses: jimschubert/delete-artifacts-action@v1 + with: + log_level: 'debug' + min_bytes: '0' + pattern: '\.xml' + + - name: Set up MySQL + if: ${{ matrix.mysql-version }} + run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/test/fixtures/custom-conf:/etc/mysql/conf.d -v $PWD/test/fixtures/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }} + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- + + - name: Install npm dependencies + run: npm ci + + - name: Wait mysql server is ready + if: ${{ matrix.mysql-version }} + run: node tools/wait-up.js + + - name: Run tests + run: FILTER=${{matrix.filter}} MYSQL_USE_TLS=${{ matrix.use-tls }} MYSQL_USE_COMPRESSION=${{ matrix.use-compression }} npm run coverage-test + + - name: get list of coverage files + run: echo "coverage-files=`find coverage | grep xml | paste -s -d\; -`" >> $GITHUB_ENV + + - name: ReportGenerator + uses: danielpalme/ReportGenerator-GitHub-Action@5.2.2 + with: + reports: "${{ env.coverage-files }}" + targetdir: '.' + reporttypes: 'Cobertura' + + - name: Debug + run: cat Cobertura.xml + + - name: Display coverage + uses: ewjoachim/coverage-comment-action@v1 + continue-on-error: true + with: + COVERAGE_FILE: "Cobertura.xml" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 3ef19aa64d..21d72b3bab 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -13,98 +13,41 @@ env: MYSQL_DATABASE: test jobs: - cleanup: - runs-on: ubuntu-latest - steps: - - name: Delete artifacts - uses: jimschubert/delete-artifacts-action@v1 - with: - log_level: 'debug' - min_bytes: '0' - pattern: '\.xml' - tests-linux: - needs: [ cleanup ] runs-on: ubuntu-latest strategy: fail-fast: false matrix: - node-version: [16.x, 18.x, 20.x] - mysql-version: ["mysql:8.0.18", "mysql:8.0.22", "mysql:8.0.33", "mysql:5.7"] - use-compression: [0] - use-tls: [0] + node-version: [14.x, 16.x, 18.x, 20.x, "21.x"] + mysql-version: ["mysql:8.0.33"] + use-compression: [0, 1] + use-tls: [0, 1] mysql_connection_url_key: [""] # TODO - add mariadb to the matrix. currently few tests are broken due to mariadb incompatibilities - include: - # 20.x - - node-version: "20.x" - mysql-version: "mysql:8.0.33" - use-compression: 1 - use-tls: 0 - use-builtin-test-runner: 1 - - node-version: "20.x" - mysql-version: "mysql:8.0.33" - use-compression: 0 - use-tls: 1 - use-builtin-test-runner: 1 - - # 18.x - # - node-version: "18.x" - # mysql_connection_url_key: "PS_MYSQL_URL" - # filter: "test-select" - # use-compression: 0 - # use-tls: 0 - - # 16.x - - node-version: "16.x" - mysql-version: "mysql:8.0.18" - use-compression: 1 - use-tls: 0 - - node-version: "16.x" - mysql-version: "mysql:8.0.18" - use-compression: 0 - use-tls: 1 - - node-version: "16.x" - mysql-version: "mysql:8.0.18" - use-compression: 1 - use-tls: 1 - - # 14.x - - node-version: "14.x" - mysql-version: "mysql:5.7" - use-compression: 0 - use-tls: 0 - - # filter - - filter: "test-select-1" # a number of tests does not work with mysql 5.1 due to old sql syntax, just testing basic connection - node-version: "16.x" - mysql-version: "datagrip/mysql:5.1" - use-compression: 0 - use-tls: 0 env: MYSQL_CONNECTION_URL: ${{ secrets[matrix.mysql_connection_url_key] }} name: Node.js ${{ matrix.node-version }} - DB ${{ matrix.mysql-version }}${{ matrix.mysql_connection_url_key }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up MySQL if: ${{ matrix.mysql-version }} run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/test/fixtures/custom-conf:/etc/mysql/conf.d -v $PWD/test/fixtures/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }} - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- - + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- + - name: Install npm dependencies run: npm ci @@ -113,45 +56,55 @@ jobs: run: node tools/wait-up.js - name: Run tests - run: FILTER=${{matrix.filter}} MYSQL_USE_TLS=${{ matrix.use-tls }} MYSQL_USE_COMPRESSION=${{ matrix.use-compression }} npm run coverage-test - - - name: Run tests with built-in node test runner - if: ${{ matrix.use-builtin-test-runner }} - run: FILTER=${{matrix.filter}} MYSQL_USE_TLS=${{ matrix.use-tls }} MYSQL_USE_COMPRESSION=${{ matrix.use-compression }} npm run test:builtin-node-runner + run: FILTER=${{matrix.filter}} MYSQL_USE_TLS=${{ matrix.use-tls }} MYSQL_USE_COMPRESSION=${{ matrix.use-compression }} npm run test - - run: echo "coverage-artifact-name=`echo -n "${{github.run_id}}-${{ matrix.node-version }}-${{ matrix.mysql-version }}-{${{ matrix.mysql_connection_url_key }}-${{matrix.use-tls}}-${{matrix.use-compression}}" | shasum | cut -d " " -f 1`" >> $GITHUB_ENV - - uses: actions/upload-artifact@v3 - with: - name: coverage-${{env.coverage-artifact-name}} - path: coverage/cobertura-coverage.xml - - coverage: - permissions: write-all - needs: [ tests-linux ] + tests-linux-bun: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + bun-version: [latest, canary] + mysql-version: ["mysql:8.0.33"] + use-compression: [0, 1] + use-tls: [0,1] + + name: Bun ${{ matrix.bun-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}} + steps: - - uses: actions/checkout@v2 - - name: Restore coverage - uses: actions/download-artifact@v2 + - uses: actions/checkout@v4 + - name: Set up MySQL + run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/test/fixtures/custom-conf:/etc/mysql/conf.d -v $PWD/test/fixtures/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }} + + - name: Set up Bun ${{ matrix.bun-version }} + uses: oven-sh/setup-bun@v1 with: - path: coverage + bun-version: ${{ matrix.bun-version }} - - name: get list of coverage files - run: echo "coverage-files=`find coverage | grep xml | paste -s -d\; -`" >> $GITHUB_ENV - - - name: ReportGenerator - uses: danielpalme/ReportGenerator-GitHub-Action@4.8.12 + - name: Set up Node.js + uses: actions/setup-node@v4 with: - reports: "${{ env.coverage-files }}" - targetdir: '.' - reporttypes: 'Cobertura' + node-version: 20 + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- - - name: Debug - run: cat Cobertura.xml + - name: Install npm dependencies + run: npm ci - - name: Display coverage - uses: ewjoachim/coverage-comment-action@v1 - continue-on-error: true - with: - COVERAGE_FILE: "Cobertura.xml" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Wait mysql server is ready + run: node tools/wait-up.js + + # todo: run full test suite once test createServer is implemented using Bun.listen + - name: run tests + env: + MYSQL_USER: ${{ env.MYSQL_USER }} + MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }} + MYSQL_PORT: ${{ env.MYSQL_PORT }} + MYSQL_USE_COMPRESSION: ${{ matrix.use-compression }} + MYSQL_USE_TLS: ${{ matrix.use-tls }} + FILTER: test-select-1|test-select-ssl + run: bun run test:bun + timeout-minutes: 1 diff --git a/.github/workflows/ci-mysql.yml b/.github/workflows/ci-mysql.yml new file mode 100644 index 0000000000..704f081141 --- /dev/null +++ b/.github/workflows/ci-mysql.yml @@ -0,0 +1,70 @@ +name: CI - MySQL + +on: + pull_request: + push: + branches: [main] + workflow_dispatch: + +env: + MYSQL_PORT: 3306 + MYSQL_USER: root + MYSQL_DATABASE: test + +jobs: + tests-linux: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: [20.x] # LTS + mysql-version: + [ + 'mysql:5.7', + 'mysql:8.0.18', + 'mysql:8.0.22', + 'mysql:8.0.33', + 'mysql:latest', + ] + use-compression: [0, 1] + use-tls: [0, 1] + mysql_connection_url_key: [''] + include: + ## MySQL 5.1: A number of tests does not work due to old sql syntax, just testing basic connection + - filter: 'test-select-1' + mysql-version: 'datagrip/mysql:5.1' + use-compression: 0 + use-tls: 0 + env: + MYSQL_CONNECTION_URL: ${{ secrets[matrix.mysql_connection_url_key] }} + + name: ${{ matrix.mysql-version }}${{ matrix.mysql_connection_url_key }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}} + + steps: + - uses: actions/checkout@v4 + + - name: Set up MySQL + if: ${{ matrix.mysql-version }} + run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/test/fixtures/custom-conf:/etc/mysql/conf.d -v $PWD/test/fixtures/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }} + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- + + - name: Install npm dependencies + run: npm ci + + - name: Wait mysql server is ready + if: ${{ matrix.mysql-version }} + run: node tools/wait-up.js + + - name: Run tests + run: FILTER=${{matrix.filter}} MYSQL_USE_TLS=${{ matrix.use-tls }} MYSQL_USE_COMPRESSION=${{ matrix.use-compression }} npm run test diff --git a/.github/workflows/ci-osx.yml b/.github/workflows/ci-osx.yml index ac7f4bba26..feb7bbc315 100644 --- a/.github/workflows/ci-osx.yml +++ b/.github/workflows/ci-osx.yml @@ -18,14 +18,14 @@ jobs: strategy: fail-fast: false matrix: - node-version: [20.x] + node-version: [20.x] # LTS use-compression: [0, 1] use-tls: [0, 1] name: Node.js ${{ matrix.node-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install MySQL run: | @@ -36,16 +36,16 @@ jobs: run: brew services start mysql@8.0 - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- + key: npm-osx-${{ hashFiles('package-lock.json') }} + restore-keys: npm-osx- - name: Install npm dependencies run: npm ci diff --git a/.github/workflows/ci-tsc-build.yml b/.github/workflows/ci-tsc-build.yml index 4f59642344..8d4483521c 100644 --- a/.github/workflows/ci-tsc-build.yml +++ b/.github/workflows/ci-tsc-build.yml @@ -13,26 +13,26 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18.x] + node-version: [20.x] name: Node.js ${{ matrix.node-version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- - + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- + - name: Install npm dependencies run: npm ci - + - name: Testing TypeScript build run: npm run test:tsc-build diff --git a/.github/workflows/ci-website.yml b/.github/workflows/ci-website.yml index 734e3dbeaa..9991dd07f1 100644 --- a/.github/workflows/ci-website.yml +++ b/.github/workflows/ci-website.yml @@ -10,19 +10,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Actions - Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Actions - Setup NodeJS - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: '18.x' + node-version: '20.x' - name: Cache Dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- + key: npm-website-${{ hashFiles('website/package-lock.json') }} + restore-keys: npm-website- - name: Installing Dependencies run: cd website && npm ci diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index d8bb876459..c13920674e 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18.x, 20.x] + node-version: [20.x] # LTS mysql-version: ['8.0'] use-compression: [0, 1] use-tls: [0, 1] @@ -26,24 +26,20 @@ jobs: name: Node.js ${{ matrix.node-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up MySQL uses: shogo82148/actions-setup-mysql@v1 with: mysql-version: ${{ matrix.mysql-version }} + - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- - + cache: 'npm' + - name: Install npm dependencies - run: npm install + run: npm ci - name: Wait mysql server is ready run: node tools/wait-up.js - run: node tools/create-db.js diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 071004f19a..972f56507a 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -12,19 +12,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Actions - Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Actions - Setup NodeJS - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: '18.x' - name: Cache Dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- + key: npm-website-${{ hashFiles('website/package-lock.json') }} + restore-keys: npm-website- - name: Installing Dependencies run: cd website && npm ci diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4b8221c185..bac684470d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,28 +4,39 @@ on: pull_request: push: branches: [ master ] + workflow_dispatch: env: - NODE_VERSION: 16.x + NODE_VERSION: 20.x jobs: lint-js: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} + - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: npm- + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- + - name: Install ESLint + ESLint configs/plugins run: npm install --only=dev + - name: Lint JS files run: npm run lint:code + - name: Lint JS snippets in docs - run: npm run lint:docs \ No newline at end of file + run: npm run lint:docs + + - name: Lint Tests + run: npm run lint:tests + + - name: Lint Typings + run: npm run lint:typings diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 69bab595eb..61fe5262d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,6 +2,7 @@ on: push: branches: - master + workflow_dispatch: name: release-please jobs: release-please: @@ -14,15 +15,22 @@ jobs: package-name: mysql2 changelog-path: 'Changelog.md' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 if: ${{ steps.release.outputs.release_created }} - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 if: ${{ steps.release.outputs.release_created }} with: - node-version: 16 + node-version: '20.x' registry-url: 'https://registry.npmjs.org' + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: npm-linux-${{ hashFiles('package-lock.json') }} + restore-keys: npm-linux- + - run: npm ci if: ${{ steps.release.outputs.release_created }} diff --git a/lib/packets/column_definition.js b/lib/packets/column_definition.js index 35b32a115f..2ff4d84efd 100644 --- a/lib/packets/column_definition.js +++ b/lib/packets/column_definition.js @@ -47,7 +47,7 @@ class ColumnDefinition { this.name = StringParser.decode( this._buf, this.encoding === 'binary' ? this._clientEncoding : this.encoding, - _nameStart, + _nameStart, _nameStart + _nameLength ); this.columnLength = packet.readInt32(); @@ -90,7 +90,7 @@ class ColumnDefinition { if (f === 'PRI_KEY') { flagNames.push('PRIMARY KEY'); } else if (f === 'NOT_NULL') { - flagNames.push('NOT NULL'); + flagNames.push('NOT NULL'); } else if (f === 'BINARY') { // ignore flag for now } else if (f === 'MULTIPLE_KEY') { @@ -98,7 +98,7 @@ class ColumnDefinition { // in the schema usually this is part of index definition // example: UNIQUE KEY `my_uniq_id` (`id_box_elements`,`id_router`) // note that only first column has MULTIPLE_KEY flag set in this case - // so there is no good way of knowing that this is part of index just + // so there is no good way of knowing that this is part of index just // by looking at indifidual field flags } else if (f === 'NO_DEFAULT_VALUE') { // almost the same as NOT_NULL? @@ -265,10 +265,10 @@ const addString = function(name) { const val = StringParser.decode( this._buf, this.encoding === 'binary' ? this._clientEncoding : this.encoding, - start, + start, end ); - + Object.defineProperty(this, name, { value: val, writable: false, diff --git a/package-lock.json b/package-lock.json index 684635bae3..732a943309 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,16 +32,45 @@ "eslint-plugin-markdown": "^3.0.0", "husky": "^9.0.2", "lint-staged": "^15.0.1", + "poku": "^1.8.1", "portfinder": "^1.0.28", "prettier": "^3.0.0", "progress": "^2.0.3", - "typescript": "^5.0.2", - "utest": "0.0.8" + "typescript": "^5.0.2" }, "engines": { "node": ">= 8.0" } }, + "../../../weslley.io/nodejs/poku": { + "version": "1.7.0", + "extraneous": true, + "license": "MIT", + "bin": { + "poku": "lib/bin/index.js" + }, + "devDependencies": { + "@types/node": "^20.11.21", + "@typescript-eslint/eslint-plugin": "^7.1.0", + "@typescript-eslint/parser": "^7.1.0", + "c8": "^9.1.0", + "eslint": "^8.57.0", + "eslint-config-prettier": "^9.1.0", + "eslint-import-resolver-typescript": "^3.6.1", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-prettier": "^5.1.3", + "packages-update": "^1.2.1", + "prettier": "^3.2.5", + "tsx": "^4.7.1", + "typescript": "^5.3.3" + }, + "engines": { + "bun": ">=0.5.3", + "deno": ">=1.17.0", + "node": ">=6.0.0", + "typescript": ">=5.0.2" + } + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -2419,6 +2448,21 @@ "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", "dev": true }, + "node_modules/poku": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/poku/-/poku-1.8.1.tgz", + "integrity": "sha512-L4WrcZYMJNXz7wj8NWXMHsflyWyv4NGGHmvtDCI5p57Lytr2BDkjxeEoum8HmdtHCIsmIk3zdUMriNu7Xj6dFw==", + "dev": true, + "bin": { + "poku": "lib/bin/index.js" + }, + "engines": { + "bun": ">=0.5.3", + "deno": ">=1.17.0", + "node": ">=6.0.0", + "typescript": ">=5.0.2" + } + }, "node_modules/portfinder": { "version": "1.0.32", "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.32.tgz", @@ -2950,15 +2994,6 @@ "punycode": "^2.1.0" } }, - "node_modules/utest": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/utest/-/utest-0.0.8.tgz", - "integrity": "sha512-ytvRS6oGpzw2OV1LsD92cr9Jfv0AVschIYo42YEaa3umHD7diWnLIK1Px24kO9eoS4EfGFyjUV15984AZOMIbA==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/v8-to-istanbul": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz", @@ -4832,6 +4867,12 @@ "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", "dev": true }, + "poku": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/poku/-/poku-1.8.1.tgz", + "integrity": "sha512-L4WrcZYMJNXz7wj8NWXMHsflyWyv4NGGHmvtDCI5p57Lytr2BDkjxeEoum8HmdtHCIsmIk3zdUMriNu7Xj6dFw==", + "dev": true + }, "portfinder": { "version": "1.0.32", "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.32.tgz", @@ -5191,12 +5232,6 @@ "punycode": "^2.1.0" } }, - "utest": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/utest/-/utest-0.0.8.tgz", - "integrity": "sha512-ytvRS6oGpzw2OV1LsD92cr9Jfv0AVschIYo42YEaa3umHD7diWnLIK1Px24kO9eoS4EfGFyjUV15984AZOMIbA==", - "dev": true - }, "v8-to-istanbul": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz", diff --git a/package.json b/package.json index 8cff47d469..fa36f4e633 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,12 @@ "lint": "npm run lint:docs && npm run lint:code", "lint:code": "eslint index.js promise.js index.d.ts promise.d.ts \"typings/**/*.ts\" \"lib/**/*.js\" \"test/**/*.{js,ts}\" \"benchmarks/**/*.js\"", "lint:docs": "eslint Contributing.md README.md", - "test": "node ./test/run.js", - "test:builtin-node-runner": "NODE_V8_COVERAGE=./coverage node --test --experimental-test-coverage test/builtin-runner", + "lint:typings": "npx prettier --check ./typings", + "lint:tests": "npx prettier --check ./test", + "test": "poku --debug --include=\"test/esm,test/unit,test/integration\"", + "test:bun": "poku --debug --platform=\"bun\" --include=\"test/esm,test/unit,test/integration\"", "test:tsc-build": "cd \"test/tsc-build\" && npx tsc -p \"tsconfig.json\"", - "coverage-test": "c8 -r cobertura -r lcov -r text node ./test/run.js", + "coverage-test": "c8 -r cobertura -r lcov -r text npm run test", "benchmark": "node ./benchmarks/benchmark.js", "prettier": "prettier --single-quote --trailing-comma none --write \"{lib,test}/**/*.js\"", "prettier:docs": "prettier --single-quote --trailing-comma none --write README.md", @@ -78,10 +80,10 @@ "eslint-plugin-markdown": "^3.0.0", "husky": "^9.0.2", "lint-staged": "^15.0.1", + "poku": "^1.8.1", "portfinder": "^1.0.28", "prettier": "^3.0.0", "progress": "^2.0.3", - "typescript": "^5.0.2", - "utest": "0.0.8" + "typescript": "^5.0.2" } } diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 1d3e10bed6..0000000000 --- a/test/.eslintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "no-console": "off" - } -} diff --git a/test/builtin-runner/integration/connection/test-column-inspect.mjs b/test/builtin-runner/integration/connection/test-column-inspect.mjs deleted file mode 100644 index 493e6711d2..0000000000 --- a/test/builtin-runner/integration/connection/test-column-inspect.mjs +++ /dev/null @@ -1,102 +0,0 @@ -import { describe, it, before, after } from 'node:test'; -import assert from 'node:assert'; -import util from 'node:util'; -import common from '../../../common.js'; - -describe( - 'custom inspect for column definition', - { timeout: 1000 }, - async () => { - let connection; - - before(async () => { - connection = await common.createConnection().promise(); - connection.query(`DROP TABLE IF EXISTS test_fields`); - }); - - after(async () => { - await connection.end(); - }); - - it('should map fields to a schema-like description when depth is > 1', async () => { - const schema = ` - id INT NOT NULL AUTO_INCREMENT, - weight INT(2) UNSIGNED ZEROFILL, - usignedInt INT UNSIGNED NOT NULL, - signedInt INT NOT NULL, - unsignedShort SMALLINT UNSIGNED NOT NULL, - signedShort SMALLINT NOT NULL, - tinyIntUnsigned TINYINT UNSIGNED NOT NULL, - tinyIntSigned TINYINT NOT NULL, - mediumIntUnsigned MEDIUMINT UNSIGNED NOT NULL, - mediumIntSigned MEDIUMINT NOT NULL, - bigIntSigned BIGINT NOT NULL, - bigIntUnsigned BIGINT UNSIGNED NOT NULL, - longText_ LONGTEXT NOT NULL, - mediumText_ MEDIUMTEXT NOT NULL, - text_ TEXT NOT NULL, - tinyText_ TINYTEXT NOT NULL, - varString_1000 VARCHAR(1000) NOT NULL, - decimalDefault DECIMAL, - decimal13_10 DECIMAL(13,10), - floatDefault FLOAT, - float11_7 FLOAT(11,7), - dummyLastFieldToAllowForTrailingComma INT, - `; - await connection.query( - `CREATE TEMPORARY TABLE test_fields (${schema} PRIMARY KEY (id))` - ); - const [_, columns] = await connection.query('select * from test_fields'); - const inspectResults = util.inspect(columns); - const schemaArray = schema - .split('\n') - .map((line) => line.trim()) - .filter((line) => line.length > 0) - .map((line) => { - const words = line.split(' '); - const name = `\`${words[0]}\``; - return [name, ...words.slice(1)].join(' '); - }); - - const normalizedInspectResults = inspectResults - .split('\n') - .slice(1, -2) // remove "[" and "]" lines and also last dummy field - .map((line) => line.trim()) - // remove primary key - it's not in the schema explicitly but worth having in inspect - .map(line => line.split('PRIMARY KEY ').join('')); - - for (let l = 0; l < normalizedInspectResults.length; l++) { - const inspectLine = normalizedInspectResults[l]; - const schemaLine = schemaArray[l]; - assert.equal(inspectLine, schemaLine); - } - }); - - it.only('should show detailed description when depth is < 1', async () => { - await connection.query(` - CREATE TEMPORARY TABLE test_fields2 ( - id INT, - decimal13_10 DECIMAL(13,10) UNSIGNED NOT NULL, - PRIMARY KEY (id) - ) - `); - const [_, columns] = await connection.query('select * from test_fields2'); - const inspectResults = util.inspect(columns[1]); - assert.deepEqual(inspectResults, util.inspect({ - catalog: 'def', - schema: 'test', - name: 'decimal13_10', - orgName: 'decimal13_10', - table: 'test_fields2', - orgTable: 'test_fields2', - characterSet: 63, - encoding: 'binary', - columnLength: 14, - type: 246, - flags: [ 'NOT NULL' ], - decimals: 10, - typeName: 'NEWDECIMAL' - })); - }); - } -); diff --git a/test/builtin-runner/integration/connection/test-execute-1.mjs b/test/builtin-runner/integration/connection/test-execute-1.mjs deleted file mode 100644 index 21c6630491..0000000000 --- a/test/builtin-runner/integration/connection/test-execute-1.mjs +++ /dev/null @@ -1,102 +0,0 @@ -import { describe, it, before, after } from 'node:test'; -import assert from 'node:assert'; -import common from '../../../common.js'; - -describe('Simple execute with parameters should return expected values', { timeout: 1000 }, () => { - let connection; - - before((t, done) => { - connection = common.createConnection(); - connection.on('error', (err) => { - done(err); - }); - connection.on('connect', () => { - done(null); - }); - }); - - after((t, done) => { - connection.end(done); - }); - - it('should execute simple SELECT 1 statement', (t, done) => { - connection.execute('SELECT 1 as test', [], (err, _rows, _fields) => { - if (err) { - return done(err); - } - assert.deepEqual(_rows, [{ test: 1 }]); - assert.equal(_fields[0].name, 'test'); - done(null); - }); - }); - - it('should execute simple SELECT 1+? statement', (t, done) => { - connection.execute('SELECT 1+? as test', [123], (err, _rows, _fields) => { - if (err) { - return done(err); - } - assert.deepEqual(_rows, [{ test: 124 }]); - assert.equal(_fields[0].name, 'test'); - done(null); - }); - }); - - it('should execute simple INSERT + SELECT statements', (t, done) => { - connection.query( - [ - 'CREATE TEMPORARY TABLE `announcements` (', - '`id` int(11) NOT NULL AUTO_INCREMENT,', - '`title` varchar(255) DEFAULT NULL,', - '`text` varchar(255) DEFAULT NULL,', - 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8', - ].join('\n'), - (err) => { - if (err) { - done(err); - } - } - ); - - connection.execute( - 'INSERT INTO announcements(title, text) VALUES(?, ?)', - ['Есть место, где заканчивается тротуар', 'Расти борода, расти'], - (err) => { - if (err) { - done(err); - } - } - ); - connection.execute( - 'INSERT INTO announcements(title, text) VALUES(?, ?)', - [ - 'Граждане Российской Федерации имеют право собираться мирно без оружия', - 'проводить собрания, митинги и демонстрации, шествия и пикетирование', - ], - (err) => { - if (err) { - done(err); - } - } - ); - - connection.execute('SELECT * FROM announcements', (err, _rows) => { - if (err) { - done(err); - } - assert.equal(_rows.length, 2); - assert.equal(_rows[0].title, 'Есть место, где заканчивается тротуар'); - assert.equal(_rows[0].text, 'Расти борода, расти'); - assert.equal( - _rows[1].title, - 'Граждане Российской Федерации имеют право собираться мирно без оружия' - ); - assert.equal( - _rows[1].text, - 'проводить собрания, митинги и демонстрации, шествия и пикетирование' - ); - - done(null); - }); - }); -}); diff --git a/test/builtin-runner/integration/pool-cluster/test-promise-wrapper.mjs b/test/builtin-runner/integration/pool-cluster/test-promise-wrapper.mjs deleted file mode 100644 index b66a661a27..0000000000 --- a/test/builtin-runner/integration/pool-cluster/test-promise-wrapper.mjs +++ /dev/null @@ -1,33 +0,0 @@ -import { describe, it, before, after } from 'node:test'; -import assert from 'node:assert'; -import common from '../../../common.js'; -import { createPoolCluster } from "../../../../promise.js" - -describe('Test pool cluster', { timeout: 1000 }, () => { - - it('should propagate warn event to promise wrapper', (t, done) => { - - const poolCluster = createPoolCluster(); - /* eslint-disable no-invalid-this */ - poolCluster - .once('warn', function () { - assert.equal(this, poolCluster); - done(); - }) - /* eslint-enable no-invalid-this */ - poolCluster.poolCluster.emit('warn', new Error()); - }); - - it('should propagate remove event to promise wrapper', (t, done) => { - - const poolCluster = createPoolCluster(); - /* eslint-disable no-invalid-this */ - poolCluster - .once('remove', function () { - assert.equal(this, poolCluster); - done(); - }); - /* eslint-enable no-invalid-this */ - poolCluster.poolCluster.emit('remove'); - }); -}); diff --git a/test/builtin-runner/regressions/2052.test.mjs b/test/builtin-runner/regressions/2052.test.mjs deleted file mode 100644 index d12865cf6c..0000000000 --- a/test/builtin-runner/regressions/2052.test.mjs +++ /dev/null @@ -1,151 +0,0 @@ -import { describe, it, beforeEach, afterEach } from 'node:test'; -import assert from 'node:assert'; -import common from '../../common.js'; -import PrepareCommand from '../../../lib/commands/prepare.js'; -import packets from '../../../lib/packets/index.js'; - -describe( - 'Unit test - prepare result with number of parameters incorrectly reported by the server', - { timeout: 1000 }, - () => { - it('should report 0 actual parameters when 1 placeholder is used in ORDER BY ?', (t, done) => { - const connection = { - sequenceId: 1, - constructor: { - statementKey: () => 0, - }, - _handshakePacket: {}, - _resetSequenceId: () => {}, - _statements: new Map(), - serverEncoding: 'utf8', - clientEncoding: 'utf8', - config: { - charsetNumber: 33, - }, - writePacket: (packet) => { - // client -> server COM_PREPARE - packet.writeHeader(1); - assert.equal( - packet.buffer.toString('hex'), - '1f0000011673656c656374202a2066726f6d207573657273206f72646572206279203f' - ); - }, - }; - const prepareCommand = new PrepareCommand( - { sql: 'select * from users order by ?' }, - (err, result) => { - assert.equal(err, null); - debugger; - assert.equal(result.parameters.length, 0); - assert.equal(result.columns.length, 51); - assert.equal(result.id, 1); - done(null); - } - ); - - prepareCommand.execute(null, connection); - const headerPacket = new packets.Packet( - 0, - Buffer.from('0000000000010000003300010000000005000002', 'hex'), - 0, - 20 - ); - prepareCommand.execute(headerPacket, connection); - const paramsEofPacket = new packets.Packet(0, Buffer.from('00000000fe000002002b000004', 'hex'), 0, 11); - prepareCommand.execute(paramsEofPacket, connection); - for (let i = 0; i < 51; ++i) { - const columnDefinitionPacket = new packets.Packet( - 0, - Buffer.from( - '0000000003646566056d7973716c0475736572047573657204486f737404486f73740ce000fc030000fe034000000005000005', 'hex' - ), - 0, - 47 - ); - prepareCommand.execute(columnDefinitionPacket, connection); - } - const columnsEofPacket = new packets.Packet(0, Buffer.from('00000000fe000002002b000004', 'hex'), 0, 11); - prepareCommand.execute(columnsEofPacket, connection); - }); - } -); - -describe('E2E Prepare result with number of parameters incorrectly reported by the server', - { timeout: 1000 }, - () => { - let connection; - - function isNewerThan8_0_22() { - const { serverVersion } = connection._handshakePacket; - const [major, minor, patch] = serverVersion.split('.').map((x) => parseInt(x, 10)); - if (major > 8) { - return true; - } - if (major === 8 && minor > 0) { - return true; - } - if (major === 8 && minor === 0 && patch >= 22) { - return true; - } - return false; - } - - beforeEach((t, done) => { - connection = common.createConnection({ - database: 'mysql', - }); - connection.on('error', (err) => { - done(err); - }); - connection.on('connect', () => { - done(null); - }); - }); - - afterEach((t, done) => { - connection.end(err => { - done(null) - }); - }); - - // see https://github.com/sidorares/node-mysql2/issues/2052#issuecomment-1620318928 - it('should report 0 actual parameters when 1 placeholder is used in ORDER BY ?', (t, done) => { - connection.prepare('select * from user order by ?', (err, stmt) => { - if (err) { - if (!err.fatal) { - connection.end(); - } - done(err); - } else { - if(isNewerThan8_0_22()) { - // mysql 8.0.22 and newer report 0 parameters - assert.equal(stmt.parameters.length, 0); - } else { - // mariadb, mysql 8.0.21 and older report 1 parameter - assert.equal(stmt.parameters.length, 1); - } - done(null); - } - }); - }); - - it('should report 1 actual parameters when 2 placeholders used in ORDER BY?', (t, done) => { - connection.prepare('select * from user where user.User like ? order by ?', (err, stmt) => { - if (err) { - if (!err.fatal) { - connection.end(); - } - done(err); - } else { - if(isNewerThan8_0_22()) { - // mysql 8.0.22 and newer report 1 parameter - assert.equal(stmt.parameters.length, 1); - } else { - // mariadb, mysql 8.0.21 and older report 2 parameters - assert.equal(stmt.parameters.length, 2); - } - done(null); - } - }); - }); -}); \ No newline at end of file diff --git a/test/common.js b/test/common.test.cjs similarity index 95% rename from test/common.js rename to test/common.test.cjs index b791aa309a..88b3750244 100644 --- a/test/common.js +++ b/test/common.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); const config = { host: process.env.MYSQL_HOST || 'localhost', @@ -42,7 +42,7 @@ exports.waitDatabaseReady = function (callback) { password: process.env.MYSQL_PASSWORD, }); - conn.once('error', err => { + conn.once('error', (err) => { if ( err.code !== 'PROTOCOL_CONNECTION_LOST' && err.code !== 'ETIMEDOUT' && @@ -188,9 +188,10 @@ exports.createTemplate = function () { const ClientFlags = require('../lib/constants/client.js'); const portfinder = require('portfinder'); + exports.createServer = function (onListening, handler) { const server = require('../index.js').createServer(); - server.on('connection', conn => { + server.on('connection', (conn) => { conn.on('error', () => { // server side of the connection // ignore disconnects @@ -220,3 +221,10 @@ exports.createServer = function (onListening, handler) { exports.useTestDb = function () { // no-op in my setup, need it for compatibility with node-mysql tests }; + +exports.version = Number(process.version.match(/v(\d+)\./)?.[1]); + +exports.describeOptions = { + icon: '🔬', + background: false, +}; diff --git a/test/esm/integration/connection/test-column-inspect.test.mjs b/test/esm/integration/connection/test-column-inspect.test.mjs new file mode 100644 index 0000000000..068a45cb81 --- /dev/null +++ b/test/esm/integration/connection/test-column-inspect.test.mjs @@ -0,0 +1,111 @@ +import { test, assert, describe, beforeEach } from 'poku'; +import util from 'node:util'; +import common from '../../../common.test.cjs'; + +(async () => { + const connection = common.createConnection().promise(); + + describe('Custom inspect for column definition', common.describeOptions); + + beforeEach( + async () => await connection.query(`DROP TABLE IF EXISTS test_fields`), + { assert: false }, + ); + + await test(async () => { + const schema = ` + id INT NOT NULL AUTO_INCREMENT, + weight INT(2) UNSIGNED ZEROFILL, + usignedInt INT UNSIGNED NOT NULL, + signedInt INT NOT NULL, + unsignedShort SMALLINT UNSIGNED NOT NULL, + signedShort SMALLINT NOT NULL, + tinyIntUnsigned TINYINT UNSIGNED NOT NULL, + tinyIntSigned TINYINT NOT NULL, + mediumIntUnsigned MEDIUMINT UNSIGNED NOT NULL, + mediumIntSigned MEDIUMINT NOT NULL, + bigIntSigned BIGINT NOT NULL, + bigIntUnsigned BIGINT UNSIGNED NOT NULL, + longText_ LONGTEXT NOT NULL, + mediumText_ MEDIUMTEXT NOT NULL, + text_ TEXT NOT NULL, + tinyText_ TINYTEXT NOT NULL, + varString_1000 VARCHAR(1000) NOT NULL, + decimalDefault DECIMAL, + decimal13_10 DECIMAL(13,10), + floatDefault FLOAT, + float11_7 FLOAT(11,7), + dummyLastFieldToAllowForTrailingComma INT, + `; + + await connection.query( + `CREATE TEMPORARY TABLE test_fields (${schema} PRIMARY KEY (id))`, + ); + + const [, columns] = await connection.query('select * from test_fields'); + const inspectResults = util.inspect(columns); + const schemaArray = schema + .split('\n') + .map((line) => line.trim()) + .filter((line) => line.length > 0) + .map((line) => { + const words = line.split(' '); + const name = `\`${words[0]}\``; + return [name, ...words.slice(1)].join(' '); + }); + + const normalizedInspectResults = inspectResults + .split('\n') + .slice(1, -2) // remove "[" and "]" lines and also last dummy field + .map((line) => line.trim()) + // remove primary key - it's not in the schema explicitly but worth having in inspect + .map((line) => line.split('PRIMARY KEY ').join('')); + + for (let l = 0; l < normalizedInspectResults.length; l++) { + const inspectLine = normalizedInspectResults[l]; + const schemaLine = schemaArray[l]; + + assert.equal( + inspectLine, + schemaLine, + 'Loop: Should map fields to a schema-like description when depth is > 1', + ); + } + }); + + common.version >= 16 && + (await test(async () => { + await connection.query(` + CREATE TEMPORARY TABLE test_fields2 ( + id INT, + decimal13_10 DECIMAL(13,10) UNSIGNED NOT NULL, + PRIMARY KEY (id) + ) + `); + + const [, columns] = await connection.query('select * from test_fields2'); + const inspectResults = util.inspect(columns[1]); + + assert.deepEqual( + inspectResults, + util.inspect({ + catalog: 'def', + schema: 'test', + name: 'decimal13_10', + orgName: 'decimal13_10', + table: 'test_fields2', + orgTable: 'test_fields2', + characterSet: 63, + encoding: 'binary', + columnLength: 14, + type: 246, + flags: ['NOT NULL'], + decimals: 10, + typeName: 'NEWDECIMAL', + }), + 'should show detailed description when depth is < 1', + ); + })); + + await connection.end(); +})(); diff --git a/test/esm/integration/connection/test-execute-1.test.mjs b/test/esm/integration/connection/test-execute-1.test.mjs new file mode 100644 index 0000000000..97682986be --- /dev/null +++ b/test/esm/integration/connection/test-execute-1.test.mjs @@ -0,0 +1,89 @@ +import { test, assert, describe } from 'poku'; +import common from '../../../common.test.cjs'; + +(async () => { + const connection = common.createConnection().promise(); + + await test(async () => { + describe( + 'Simple execute should return expected values', + common.describeOptions, + ); + + const [_rows, _fields] = await connection.execute('SELECT 1 as test'); + + assert.deepEqual( + _rows, + [{ test: 1 }], + 'should execute simple SELECT 1 statement', + ); + assert.equal(_fields[0].name, 'test', 'should field name test'); + }); + + await test(async () => { + describe( + 'Simple execute with parameters should return expected values', + common.describeOptions, + ); + + const [_rows, _fields] = await connection.execute('SELECT 1+? as test', [ + 123, + ]); + + assert.deepEqual( + _rows, + [{ test: 124 }], + 'should execute simple SELECT 1+? statement', + ); + assert.equal(_fields[0].name, 'test', 'should field name test'); + }); + + await test(async () => { + describe( + 'should execute simple INSERT + SELECT statements', + common.describeOptions, + ); + + await connection.query( + [ + 'CREATE TEMPORARY TABLE `announcements` (', + '`id` int(11) NOT NULL AUTO_INCREMENT,', + '`title` varchar(255) DEFAULT NULL,', + '`text` varchar(255) DEFAULT NULL,', + 'PRIMARY KEY (`id`)', + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), + ); + + await connection.execute( + 'INSERT INTO announcements(title, text) VALUES(?, ?)', + ['Есть место, где заканчивается тротуар', 'Расти борода, расти'], + ); + connection.execute('INSERT INTO announcements(title, text) VALUES(?, ?)', [ + 'Граждане Российской Федерации имеют право собираться мирно без оружия', + 'проводить собрания, митинги и демонстрации, шествия и пикетирование', + ]); + + const [_rows] = await connection.execute('SELECT * FROM announcements'); + + assert.equal(_rows.length, 2, 'rows length needs to be 2'); + assert.equal( + _rows[0].title, + 'Есть место, где заканчивается тротуар', + 'first row title', + ); + assert.equal(_rows[0].text, 'Расти борода, расти', 'first row text'); + assert.equal( + _rows[1].title, + 'Граждане Российской Федерации имеют право собираться мирно без оружия', + 'second row title', + ); + assert.equal( + _rows[1].text, + 'проводить собрания, митинги и демонстрации, шествия и пикетирование', + 'second row text', + ); + }); + + await connection.end(); +})(); diff --git a/test/esm/integration/named-placeholders.test.mjs b/test/esm/integration/named-placeholders.test.mjs new file mode 100644 index 0000000000..7204f287f9 --- /dev/null +++ b/test/esm/integration/named-placeholders.test.mjs @@ -0,0 +1,128 @@ +// TODO: `namedPlaceholders` can't be disabled at query level +import { assert, test, describe } from 'poku'; +import { + createConnection, + describeOptions, + createPool, +} from '../../common.test.cjs'; + +const query = + 'SELECT result FROM (SELECT 1 as result) temp WHERE temp.result=:named'; +const values = { named: 1 }; + +describe( + 'Test namedPlaceholder as command parameter in connection', + describeOptions, +); + +// test(() => { +// const c = createConnection({ namedPlaceholders: true }); + +// c.query({ sql: query, namedPlaceholders: false }, values, (err) => { +// c.end(); + +// assert( +// err || err?.sqlMessage.match(/right syntax to use near ':named'/), +// 'Enabled in connection config, disabled in query command', +// ); +// }); +// }); + +test(() => { + const c = createConnection({ namedPlaceholders: false }); + + c.query({ sql: query, namedPlaceholders: true }, values, (err, rows) => { + c.end(); + + assert.ifError(err); + assert.equal( + rows[0].result, + 1, + 'Disabled in connection config, enabled in query command', + ); + }); +}); + +// test(() => { +// const c = createConnection({ namedPlaceholders: true }); + +// c.execute({ sql: query, namedPlaceholders: false }, values, (err) => { +// c.end(); + +// assert( +// err || err?.sqlMessage.match(/right syntax to use near ':named'/), +// 'Enabled in connection config, disabled in execute command', +// ); +// }); +// }); + +test(() => { + const c = createConnection({ namedPlaceholders: false }); + + c.execute({ sql: query, namedPlaceholders: true }, values, (err, rows) => { + c.end(); + + assert.ifError(err); + assert.equal( + rows[0].result, + 1, + 'Disabled in connection config, enabled in execute command', + ); + }); +}); + +// test(() => { +// const c = createPool({ namedPlaceholders: true }); + +// c.query({ sql: query, namedPlaceholders: false }, values, (err) => { +// c.end(); + +// assert( +// err || err?.sqlMessage.match(/right syntax to use near ':named'/), +// 'Enabled in pool config, disabled in query command', +// ); +// }); +// }); + +test(() => { + const c = createPool({ namedPlaceholders: false }); + + c.query({ sql: query, namedPlaceholders: true }, values, (err, rows) => { + c.end(); + + assert.ifError(err); + assert.equal( + rows[0].result, + 1, + 'Disabled in pool config, enabled in query command', + ); + }); +}); + +// test(() => { +// const c = createPool({ namedPlaceholders: true }); + +// c.execute({ sql: query, namedPlaceholders: false }, values, (err) => { +// c.end(); + +// assert( +// err || err?.sqlMessage.match(/right syntax to use near ':named'/), +// 'Enabled in pool config, disabled in execute command', +// ); +// }); +// }); + +test(() => { + const c = createPool({ namedPlaceholders: false }); + + c.execute({ sql: query, namedPlaceholders: true }, values, (err, rows) => { + c.end(); + + assert.ifError(err); + assert.equal( + rows[0].result, + 1, + 'Disabled in pool config, enabled in execute command', + ); + }); +}); diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs new file mode 100644 index 0000000000..1a900cc857 --- /dev/null +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -0,0 +1,43 @@ +import { test, assert, describe } from 'poku'; +import { createPoolCluster } from '../../../../promise.js'; +import common from '../../../common.test.cjs'; + +(async () => { + describe('Test pool cluster', common.describeOptions); + + await test(async () => { + const poolCluster = createPoolCluster(); + + poolCluster.once('warn', async function () { + await new Promise((resolve) => { + assert.equal( + // eslint-disable-next-line no-invalid-this + this, + poolCluster, + 'should propagate warn event to promise wrapper', + ); + resolve(true); + }); + }); + + poolCluster.poolCluster.emit('warn', new Error()); + }); + + await test(async () => { + const poolCluster = createPoolCluster(); + + poolCluster.once('remove', async function () { + await new Promise((resolve) => { + assert.equal( + // eslint-disable-next-line no-invalid-this + this, + poolCluster, + 'should propagate remove event to promise wrapper', + ); + resolve(true); + }); + }); + + poolCluster.poolCluster.emit('remove'); + }); +})(); diff --git a/test/esm/integration/test-pool.test.mjs b/test/esm/integration/test-pool.test.mjs new file mode 100644 index 0000000000..d10362d379 --- /dev/null +++ b/test/esm/integration/test-pool.test.mjs @@ -0,0 +1,76 @@ +import { assert, test, describe } from 'poku'; +import mysql from '../../../index.js'; +import { describeOptions } from '../../common.test.cjs'; + +const poolConfig = {}; // config: { connectionConfig: {} }; + +const pool = mysql.createPool(poolConfig); + +describe('Pool methods tests', describeOptions); + +assert.equal(pool.escape(123), '123', 'escape method works correctly'); + +assert.equal( + pool.escapeId('table name'), + '`table name`', + 'escapeId method works correctly', +); + +test(() => { + const params = ['table name', 'thing']; + assert.equal( + pool.format('SELECT a FROM ?? WHERE b = ?', params), + "SELECT a FROM `table name` WHERE b = 'thing'", + 'format method works correctly', + ); +}); + +const poolDotPromise = pool.promise(); + +describe('Pool.promise() methods tests', describeOptions); + +assert.equal( + poolDotPromise.escape(123), + '123', + 'promise escape method works correctly', +); + +assert.equal( + poolDotPromise.escapeId('table name'), + '`table name`', + 'promise escapeId method works correctly', +); + +test(() => { + const params = ['table name', 'thing']; + assert.equal( + poolDotPromise.format('SELECT a FROM ?? WHERE b = ?', params), + "SELECT a FROM `table name` WHERE b = 'thing'", + 'promise format method works correctly', + ); +}); + +const promisePool = mysql.createPoolPromise(poolConfig); + +describe('PromisePool methods tests', describeOptions); + +assert.equal( + promisePool.escape(123), + '123', + 'PromisePool escape method works correctly', +); + +assert.equal( + promisePool.escapeId('table name'), + '`table name`', + 'PromisePool escapeId method works correctly', +); + +test(() => { + const params = ['table name', 'thing']; + assert.equal( + promisePool.format('SELECT a FROM ?? WHERE b = ?', params), + "SELECT a FROM `table name` WHERE b = 'thing'", + 'PromisePool format method works correctly', + ); +}); diff --git a/test/esm/regressions/2052.test.mjs b/test/esm/regressions/2052.test.mjs new file mode 100644 index 0000000000..c8472721ab --- /dev/null +++ b/test/esm/regressions/2052.test.mjs @@ -0,0 +1,189 @@ +import { assert, describe, test } from 'poku'; +import common from '../../common.test.cjs'; +import PrepareCommand from '../../../lib/commands/prepare.js'; +import packets from '../../../lib/packets/index.js'; + +(async () => { + await test(async () => { + describe( + 'Unit Test - Prepare result with number of parameters incorrectly reported by the server', + common.describeOptions, + ); + + const connection = { + sequenceId: 1, + constructor: { + statementKey: () => 0, + }, + _handshakePacket: {}, + _resetSequenceId: () => {}, + _statements: new Map(), + serverEncoding: 'utf8', + clientEncoding: 'utf8', + config: { + charsetNumber: 33, + }, + writePacket: (packet) => { + // client -> server COM_PREPARE + packet.writeHeader(1); + assert.equal( + packet.buffer.toString('hex'), + '1f0000011673656c656374202a2066726f6d207573657273206f72646572206279203f', + 'should report 0 actual parameters when 1 placeholder is used in ORDER BY ?', + ); + }, + }; + + await new Promise((resolve, reject) => { + const prepareCommand = new PrepareCommand( + { sql: 'select * from users order by ?' }, + (err, result) => { + try { + assert.equal(err, null, 'expect no error'); + + assert.equal(result.parameters.length, 0, 'parameters'); + assert.equal(result.columns.length, 51, 'columns'); + assert.equal(result.id, 1, 'id'); + + resolve(null); + } catch (error) { + reject(error); + } + }, + ); + + prepareCommand.execute(null, connection); + const headerPacket = new packets.Packet( + 0, + Buffer.from('0000000000010000003300010000000005000002', 'hex'), + 0, + 20, + ); + prepareCommand.execute(headerPacket, connection); + const paramsEofPacket = new packets.Packet( + 0, + Buffer.from('00000000fe000002002b000004', 'hex'), + 0, + 11, + ); + prepareCommand.execute(paramsEofPacket, connection); + for (let i = 0; i < 51; ++i) { + const columnDefinitionPacket = new packets.Packet( + 0, + Buffer.from( + '0000000003646566056d7973716c0475736572047573657204486f737404486f73740ce000fc030000fe034000000005000005', + 'hex', + ), + 0, + 47, + ); + prepareCommand.execute(columnDefinitionPacket, connection); + } + const columnsEofPacket = new packets.Packet( + 0, + Buffer.from('00000000fe000002002b000004', 'hex'), + 0, + 11, + ); + prepareCommand.execute(columnsEofPacket, connection); + }); + }); + + const connection = common.createConnection({ + database: 'mysql', + }); + + const isNewerThan8_0_22 = async () => { + const { serverVersion } = await connection._handshakePacket; + const [major, minor, patch] = serverVersion + .split('.') + .map((x) => parseInt(x, 10)); + if (major > 8) { + return true; + } + if (major === 8 && minor > 0) { + return true; + } + if (major === 8 && minor === 0 && patch >= 22) { + return true; + } + return false; + }; + + await test( + async () => + new Promise((resolve, reject) => { + describe( + 'E2E Prepare result with number of parameters incorrectly reported by the server', + common.describeOptions, + ); + + connection.prepare( + 'select * from user order by ?', + async (err, stmt) => { + if (err) { + connection.end(); + reject(err); + + return; + } + + if (await isNewerThan8_0_22()) { + assert.equal( + stmt.parameters.length, + 0, + 'parameters length needs to be 0', + 'should report 0 actual parameters when 1 placeholder is used in ORDER BY ?', + ); + } else { + assert.equal( + stmt.parameters.length, + 1, + 'parameters length needs to be 1', + ); + } + + resolve(null); + }, + ); + }), + ); + + await test( + async () => + new Promise((resolve, reject) => { + connection.prepare( + 'select * from user where user.User like ? order by ?', + async (err, stmt) => { + if (err) { + connection.end(); + reject(err); + + return; + } + + if (await isNewerThan8_0_22()) { + assert.equal( + stmt.parameters.length, + 1, + 'parameters length needs to be 1', + 'should report 1 actual parameters when 2 placeholders used in ORDER BY?', + ); + } else { + assert.equal( + stmt.parameters.length, + 2, + 'parameters length needs to be 2', + ); + } + + resolve(null); + }, + ); + }), + ); + + connection.end((err) => { + assert.ifError(err); + }); +})(); diff --git a/test/esm/unit/check-extensions.test.mjs b/test/esm/unit/check-extensions.test.mjs new file mode 100644 index 0000000000..0708fdeb6e --- /dev/null +++ b/test/esm/unit/check-extensions.test.mjs @@ -0,0 +1,35 @@ +import { EOL } from 'node:os'; +import { listFiles, assert } from 'poku'; + +const invalidFiles = []; +const message = [ + 'Check for invalid file types found in restricted directories', +]; + +const checkExtensions = ( + dirs, + allowedExtensions, + ignoreList = /\.DS_Store/, +) => { + dirs.forEach((dir) => { + const files = listFiles(dir, { filter: /\./ }); + + files.forEach((file) => { + if (!ignoreList.test(file) && !allowedExtensions.test(file)) { + invalidFiles.push(file); + message.push(`${EOL}${String(allowedExtensions)}`); + message.push(`- ${file}`); + } + }); + }); +}; + +checkExtensions(['test/unit', 'test/integration'], /\.test\.cjs$/); +checkExtensions(['test/esm'], /\.test\.mjs$/); +checkExtensions(['test/tsc-build'], /(\.test\.ts|tsconfig\.json)$/); + +assert.deepStrictEqual( + invalidFiles.length, + 0, + Array.from(new Set(message)).join(EOL), +); diff --git a/test/esm/unit/protocol/SqlString.test.mjs b/test/esm/unit/protocol/SqlString.test.mjs new file mode 100644 index 0000000000..1035e1c738 --- /dev/null +++ b/test/esm/unit/protocol/SqlString.test.mjs @@ -0,0 +1,208 @@ +import { assert, test, describe } from 'poku'; +import { describeOptions, SqlString } from '../../../common.test.cjs'; + +describe('SqlString.escapeId tests', describeOptions); + +assert.equal(SqlString.escapeId('id'), '`id`', 'value is quoted'); + +assert.equal( + SqlString.escapeId('i`d'), + '`i``d`', + 'value containing escapes is quoted', +); + +assert.equal( + SqlString.escapeId('id1.id2'), + '`id1`.`id2`', + 'value containing separator is quoted', +); + +assert.equal( + SqlString.escapeId('id`1.i`d2'), + '`id``1`.`i``d2`', + 'value containing separator and escapes is quoted', +); + +assert.equal( + SqlString.escapeId(['a', 'b', 't.c']), + '`a`, `b`, `t`.`c`', + 'arrays are turned into lists', +); + +assert.equal( + SqlString.escapeId(['a', ['b', ['t.c']]]), + '`a`, `b`, `t`.`c`', + 'nested arrays are flattened', +); + +describe('SqlString.escape tests', describeOptions); + +assert.equal(SqlString.escape(undefined), 'NULL', 'undefined -> NULL'); + +assert.equal(SqlString.escape(null), 'NULL', 'null -> NULL'); + +assert.equal( + SqlString.escape(false), + 'false', + 'booleans convert to strings (false)', +); +assert.equal( + SqlString.escape(true), + 'true', + 'booleans convert to strings (true)', +); + +assert.equal(SqlString.escape(5), '5', 'numbers convert to strings'); + +assert.equal( + SqlString.escape({ a: 'b', c: 'd' }), + "`a` = 'b', `c` = 'd'", + 'objects are turned into key value pairs', +); + +assert.equal( + SqlString.escape({ a: 'b', c: function () {} }), + "`a` = 'b'", + 'objects function properties are ignored', +); + +assert.equal( + SqlString.escape({ a: { nested: true } }), + "`a` = '[object Object]'", + 'nested objects are cast to strings', +); + +assert.equal( + SqlString.escape([1, 2, 'c']), + "1, 2, 'c'", + 'arrays are turned into lists', +); + +assert.equal( + SqlString.escape([ + [1, 2, 3], + [4, 5, 6], + ['a', 'b', { nested: true }], + ]), + "(1, 2, 3), (4, 5, 6), ('a', 'b', '[object Object]')", + 'nested arrays are turned into grouped lists', +); + +assert.equal( + SqlString.escape([1, { nested: true }, 2]), + "1, '[object Object]', 2", + 'nested objects inside arrays are cast to strings', +); + +assert.equal(SqlString.escape('Super'), "'Super'", 'strings are quoted'); + +assert.equal(SqlString.escape('Sup\0er'), "'Sup\\0er'", '\0 gets escaped'); + +assert.equal(SqlString.escape('Sup\ber'), "'Sup\\ber'", '\b gets escaped'); + +assert.equal(SqlString.escape('Sup\ner'), "'Sup\\ner'", '\n gets escaped'); + +assert.equal(SqlString.escape('Sup\rer'), "'Sup\\rer'", '\r gets escaped'); + +assert.equal(SqlString.escape('Sup\ter'), "'Sup\\ter'", '\t gets escaped'); + +assert.equal(SqlString.escape('Sup\\er'), "'Sup\\\\er'", '\\ gets escaped'); + +assert.equal( + SqlString.escape('Sup\u001aer'), + "'Sup\\Zer'", + '\u001a (ascii 26) gets replaced with \\Z', +); + +assert.equal( + SqlString.escape("Sup'er"), + "'Sup\\'er'", + 'single quotes get escaped', +); + +assert.equal( + SqlString.escape('Sup"er'), + "'Sup\\\"er'", + 'double quotes get escaped', +); + +test(() => { + const expected = '2012-05-07 11:42:03.002'; + const date = new Date(2012, 4, 7, 11, 42, 3, 2); + const string = SqlString.escape(date); + assert.strictEqual( + string, + `'${expected}'`, + 'dates are converted to YYYY-MM-DD HH:II:SS.sss', + ); +}); + +test(() => { + const buffer = Buffer.from([0, 1, 254, 255]); + const string = SqlString.escape(buffer); + assert.strictEqual(string, "X'0001feff'", 'buffers are converted to hex'); +}); + +assert.equal(SqlString.escape(NaN), 'NaN', 'NaN -> NaN'); + +assert.equal(SqlString.escape(Infinity), 'Infinity', 'Infinity -> Infinity'); + +describe('SqlString.format tests', describeOptions); + +test(() => { + const sql = SqlString.format('? and ?', ['a', 'b']); + assert.equal( + sql, + "'a' and 'b'", + 'question marks are replaced with escaped array values', + ); +}); + +test(() => { + const sql = SqlString.format('? and ?', ['a']); + assert.equal(sql, "'a' and ?", 'extra question marks are left untouched'); +}); + +test(() => { + const sql = SqlString.format('? and ?', ['a', 'b', 'c']); + assert.equal(sql, "'a' and 'b'", 'extra arguments are not used'); +}); + +test(() => { + const sql = SqlString.format('? and ?', ['hello?', 'b']); + assert.equal( + sql, + "'hello?' and 'b'", + 'question marks within values do not cause issues', + ); +}); + +test(() => { + const sql = SqlString.format('?', undefined); + assert.equal(sql, '?', 'undefined is ignored'); +}); + +test(() => { + const sql = SqlString.format('?', { hello: 'world' }); + assert.equal(sql, "`hello` = 'world'", 'objects is converted to values'); +}); + +test(() => { + const sql = SqlString.format('?', { hello: 'world' }, true); + assert.equal( + sql, + "'[object Object]'", + 'objects is not converted to values when flag is true', + ); + + const sql2 = SqlString.format( + '?', + { + toString: function () { + return 'hello'; + }, + }, + true, + ); + assert.equal(sql2, "'hello'", 'custom toString function is respected'); +}); diff --git a/test/integration/config/test-connect-timeout.js b/test/integration/config/test-connect-timeout.test.cjs similarity index 67% rename from test/integration/config/test-connect-timeout.js rename to test/integration/config/test-connect-timeout.test.cjs index 743a11cbe1..c53f46db6e 100644 --- a/test/integration/config/test-connect-timeout.js +++ b/test/integration/config/test-connect-timeout.test.cjs @@ -1,8 +1,10 @@ 'use strict'; const portfinder = require('portfinder'); -const assert = require('assert'); const mysql = require('../../../index.js'); +// Poku intentionally doesn't allow "rewriting" after uncaughtException +const assert = require('assert'); + console.log('test connect timeout'); portfinder.getPort((err, port) => { @@ -13,13 +15,13 @@ portfinder.getPort((err, port) => { server.listen(port); - const connection = mysql.createConnection({ + const connection = mysql.createConnection({ host: 'localhost', port: port, connectTimeout: 1000, }); - connection.on('error', err => { + connection.on('error', (err) => { assert.equal(err.code, 'ETIMEDOUT'); connection.destroy(); server._server.close(); @@ -27,7 +29,10 @@ portfinder.getPort((err, port) => { }); }); -process.on('uncaughtException', err => { - assert.equal(err.message, 'Connection lost: The server closed the connection.'); +process.on('uncaughtException', (err) => { + assert.equal( + err.message, + 'Connection lost: The server closed the connection.', + ); assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); }); diff --git a/test/integration/config/test-typecast-global-option.js b/test/integration/config/test-typecast-global-option.test.cjs similarity index 63% rename from test/integration/config/test-typecast-global-option.js rename to test/integration/config/test-typecast-global-option.test.cjs index f9813df961..ec5105b5e7 100644 --- a/test/integration/config/test-typecast-global-option.js +++ b/test/integration/config/test-typecast-global-option.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const typeCastWrapper = function(stringMethod) { - return function(field, next) { +const typeCastWrapper = function (stringMethod) { + return function (field, next) { if (field.type === 'VAR_STRING') { return field.string()[stringMethod](); } @@ -9,34 +9,34 @@ const typeCastWrapper = function(stringMethod) { }; }; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ - typeCast: typeCastWrapper('toUpperCase') + typeCast: typeCastWrapper('toUpperCase'), }); -const assert = require('assert'); +const { assert } = require('poku'); // query option override global typeCast connection.query( { sql: 'select "FOOBAR" as foo', - typeCast: typeCastWrapper('toLowerCase') + typeCast: typeCastWrapper('toLowerCase'), }, (err, res) => { assert.ifError(err); assert.equal(res[0].foo, 'foobar'); - } + }, ); // global typecast works connection.query( { - sql: 'select "foobar" as foo' + sql: 'select "foobar" as foo', }, (err, res) => { assert.ifError(err); assert.equal(res[0].foo, 'FOOBAR'); - } + }, ); connection.end(); diff --git a/test/integration/connection/encoding/test-charset-results.js b/test/integration/connection/encoding/test-charset-results.test.cjs similarity index 92% rename from test/integration/connection/encoding/test-charset-results.js rename to test/integration/connection/encoding/test-charset-results.test.cjs index c62091969f..1d222f34ad 100644 --- a/test/integration/connection/encoding/test-charset-results.js +++ b/test/integration/connection/encoding/test-charset-results.test.cjs @@ -6,14 +6,14 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { } const mysql = require('../../../../index.js'); -const common = require('../../../common'); +const common = require('../../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const payload = 'привет, мир'; function tryEncoding(encoding, cb) { - connection.query('set character_set_results = ?', [encoding], err => { + connection.query('set character_set_results = ?', [encoding], (err) => { assert.ifError(err); connection.query('SELECT ?', [payload], (err, rows, fields) => { assert.ifError(err); @@ -23,7 +23,7 @@ function tryEncoding(encoding, cb) { } assert.equal( mysql.CharsetToEncoding[fields[0].characterSet], - iconvEncoding + iconvEncoding, ); assert.equal(fields[0].name, payload); assert.equal(rows[0][fields[0].name], payload); @@ -33,7 +33,7 @@ function tryEncoding(encoding, cb) { } function tryEncodingExecute(encoding, cb) { - connection.execute('set character_set_results = ?', [encoding], err => { + connection.execute('set character_set_results = ?', [encoding], (err) => { assert.ifError(err); connection.execute('SELECT ? as n', [payload], (err, rows, fields) => { assert.ifError(err); @@ -43,7 +43,7 @@ function tryEncodingExecute(encoding, cb) { } assert.equal( mysql.CharsetToEncoding[fields[0].characterSet], - iconvEncoding + iconvEncoding, ); // TODO: figure out correct metadata encodings setup for binary protocol // assert.equal(fields[0].name, payload); diff --git a/test/integration/connection/encoding/test-client-encodings.js b/test/integration/connection/encoding/test-client-encodings.test.cjs similarity index 78% rename from test/integration/connection/encoding/test-client-encodings.js rename to test/integration/connection/encoding/test-client-encodings.test.cjs index de382d6084..780becd7fb 100644 --- a/test/integration/connection/encoding/test-client-encodings.js +++ b/test/integration/connection/encoding/test-client-encodings.test.cjs @@ -5,30 +5,30 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const common = require('../../../common'); -const assert = require('assert'); +const common = require('../../../common.test.cjs'); +const { assert } = require('poku'); const connection = common.createConnection({ charset: 'UTF8MB4_GENERAL_CI' }); connection.query('drop table if exists __test_client_encodings'); connection.query( 'create table if not exists __test_client_encodings (name VARCHAR(200)) CHARACTER SET=utf8mb4', - err => { + (err) => { assert.ifError(err); - connection.query('delete from __test_client_encodings', err => { + connection.query('delete from __test_client_encodings', (err) => { assert.ifError(err); connection.end(); const connection1 = common.createConnection({ - charset: 'CP1251_GENERAL_CI' + charset: 'CP1251_GENERAL_CI', }); connection1.query( 'insert into __test_client_encodings values("привет, мир")', - err => { + (err) => { assert.ifError(err); connection1.end(); const connection2 = common.createConnection({ - charset: 'KOI8R_GENERAL_CI' + charset: 'KOI8R_GENERAL_CI', }); connection2.query( 'select * from __test_client_encodings', @@ -36,10 +36,10 @@ connection.query( assert.ifError(err); assert.equal(rows[0].name, 'привет, мир'); connection2.end(); - } + }, ); - } + }, ); }); - } + }, ); diff --git a/test/integration/connection/encoding/test-non-bmp-chars.js b/test/integration/connection/encoding/test-non-bmp-chars.test.cjs similarity index 89% rename from test/integration/connection/encoding/test-non-bmp-chars.js rename to test/integration/connection/encoding/test-non-bmp-chars.test.cjs index 457280eae0..c3d5a5232c 100644 --- a/test/integration/connection/encoding/test-non-bmp-chars.js +++ b/test/integration/connection/encoding/test-non-bmp-chars.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const common = require('../../../common'); -const assert = require('assert'); +const common = require('../../../common.test.cjs'); +const { assert } = require('poku'); if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { console.log('skipping test for planetscale'); diff --git a/test/integration/connection/encoding/test-track-encodings.js b/test/integration/connection/encoding/test-track-encodings.test.cjs similarity index 70% rename from test/integration/connection/encoding/test-track-encodings.js rename to test/integration/connection/encoding/test-track-encodings.test.cjs index f48638dd6c..29925c63e1 100644 --- a/test/integration/connection/encoding/test-track-encodings.js +++ b/test/integration/connection/encoding/test-track-encodings.test.cjs @@ -1,17 +1,17 @@ 'use strict'; -const common = require('../../../common'); -const assert = require('assert'); +const common = require('../../../common.test.cjs'); +const { assert } = require('poku'); const connection = common.createConnection({ charset: 'UTF8MB4_GENERAL_CI' }); const text = 'привет, мир'; -connection.query('SET character_set_client=koi8r', err => { +connection.query('SET character_set_client=koi8r', (err) => { assert.ifError(err); connection.query(`SELECT ? as result`, [text], (err, rows) => { assert.ifError(err); assert.equal(rows[0].result, text); - connection.query('SET character_set_client=cp1251', err => { + connection.query('SET character_set_client=cp1251', (err) => { assert.ifError(err); connection.query(`SELECT ? as result`, [text], (err, rows) => { assert.ifError(err); diff --git a/test/integration/connection/test-binary-charset-string.js b/test/integration/connection/test-binary-charset-string.test.cjs similarity index 96% rename from test/integration/connection/test-binary-charset-string.js rename to test/integration/connection/test-binary-charset-string.test.cjs index b641660656..0a8906b5cd 100644 --- a/test/integration/connection/test-binary-charset-string.js +++ b/test/integration/connection/test-binary-charset-string.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); // TODO - this could be re-enabled if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { diff --git a/test/integration/connection/test-binary-longlong.js b/test/integration/connection/test-binary-longlong.test.cjs similarity index 85% rename from test/integration/connection/test-binary-longlong.js rename to test/integration/connection/test-binary-longlong.test.cjs index 5ae028545b..c76ca35281 100644 --- a/test/integration/connection/test-binary-longlong.js +++ b/test/integration/connection/test-binary-longlong.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); -const common = require('../../common'); +const common = require('../../common.test.cjs'); const conn = common.createConnection(); conn.query( @@ -11,7 +11,7 @@ conn.query( ' `ls` BIGINT SIGNED, ' + ' `lu` BIGINT UNSIGNED, ' + ' PRIMARY KEY (`id`) ' + - ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8' + ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8', ); const values = [ @@ -19,10 +19,10 @@ const values = [ ['-11', '11'], ['965432100123456789', '1965432100123456789'], ['-965432100123456789', '2965432100123456789'], - [null, null] + [null, null], ]; -conn.connect(err => { +conn.connect((err) => { if (err) { console.error(err); return; @@ -32,7 +32,7 @@ conn.connect(err => { conn.query('INSERT INTO `tmp_longlong` VALUES (?, ?, ?)', [ i + 1, values[i][0], - values[i][1] + values[i][1], ]); } @@ -41,7 +41,7 @@ conn.connect(err => { { id: 2, ls: -11, lu: 11 }, { id: 3, ls: 965432100123456800, lu: 1965432100123456800 }, { id: 4, ls: -965432100123456800, lu: 2965432100123457000 }, - { id: 5, ls: null, lu: null } + { id: 5, ls: null, lu: null }, ]; const bigNums_bnStringsTrueFalse = [ @@ -49,7 +49,7 @@ conn.connect(err => { { id: 2, ls: -11, lu: 11 }, { id: 3, ls: '965432100123456789', lu: '1965432100123456789' }, { id: 4, ls: '-965432100123456789', lu: '2965432100123456789' }, - { id: 5, ls: null, lu: null } + { id: 5, ls: null, lu: null }, ]; const bigNums_bnStringsTrueTrue = [ @@ -57,7 +57,7 @@ conn.connect(err => { { id: 2, ls: -11, lu: 11 }, { id: 3, ls: '965432100123456789', lu: '1965432100123456789' }, { id: 4, ls: '-965432100123456789', lu: '2965432100123456789' }, - { id: 5, ls: null, lu: null } + { id: 5, ls: null, lu: null }, ]; let completed = 0; @@ -69,7 +69,7 @@ conn.connect(err => { { sql: 'SELECT * from tmp_longlong', supportBigNumbers: supportBigNumbers, - bigNumberStrings: bigNumberStrings + bigNumberStrings: bigNumberStrings, }, (err, rows) => { assert.ifError(err); @@ -78,7 +78,7 @@ conn.connect(err => { if (completed === started) { conn.end(); } - } + }, ); } @@ -88,7 +88,7 @@ conn.connect(err => { { sql: 'SELECT * from tmp_longlong', supportBigNumbers: supportBigNumbers, - bigNumberStrings: bigNumberStrings + bigNumberStrings: bigNumberStrings, }, (err, rows) => { assert.ifError(err); @@ -97,7 +97,7 @@ conn.connect(err => { if (completed === started) { conn.end(); } - } + }, ); } diff --git a/test/integration/connection/test-binary-multiple-results.js b/test/integration/connection/test-binary-multiple-results.test.cjs similarity index 90% rename from test/integration/connection/test-binary-multiple-results.js rename to test/integration/connection/test-binary-multiple-results.test.cjs index 4351e092cb..ef211bf82b 100644 --- a/test/integration/connection/test-binary-multiple-results.js +++ b/test/integration/connection/test-binary-multiple-results.test.cjs @@ -10,8 +10,8 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const mysql = require('../../common.js').createConnection({ - multipleStatements: true +const mysql = require('../../common.test.cjs').createConnection({ + multipleStatements: true, }); const assert = require('assert-diff'); mysql.query('CREATE TEMPORARY TABLE no_rows (test int)'); @@ -20,7 +20,7 @@ mysql.query('INSERT INTO some_rows values(0)'); mysql.query('INSERT INTO some_rows values(42)'); mysql.query('INSERT INTO some_rows values(314149)'); -const clone = function(obj) { +const clone = function (obj) { return JSON.parse(JSON.stringify(obj)); }; @@ -31,15 +31,15 @@ const rs1 = { serverStatus: 10, warningStatus: 0, info: '', - changedRows: 0 + changedRows: 0, }; const rs2 = clone(rs1); rs2.serverStatus = 2; const rs3 = clone(rs1); rs3.serverStatus = 34; -const select1 = [{ '1': '1' }]; -const select2 = [{ '2': '2' }]; +const select1 = [{ 1: '1' }]; +const select2 = [{ 2: '2' }]; const fields1 = [ { catalog: 'def', @@ -52,8 +52,8 @@ const fields1 = [ orgName: '', orgTable: '', schema: '', - table: '' - } + table: '', + }, ]; const nr_fields = [ { @@ -67,8 +67,8 @@ const nr_fields = [ orgName: 'test', orgTable: 'no_rows', schema: mysql.config.database, - table: 'no_rows' - } + table: 'no_rows', + }, ]; const sr_fields = clone(nr_fields); @@ -83,13 +83,13 @@ const tests = [ ['select * from some_rows', [[select3, rs3], [sr_fields, undefined], 2]], // select 3 rows [ 'SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT; SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS', - [rs2, undefined, 1] + [rs2, undefined, 1], ], ['set @a = 1', [rs2, undefined, 1]], ['set @a = 1; set @b = 2', [rs2, undefined, 1]], [ 'select 1; select 2', - [[select1, select2, rs2], [fields1, fields2, undefined], 3] + [[select1, select2, rs2], [fields1, fields2, undefined], 3], ], ['set @a = 1; select 1', [[select1, rs2], [fields1, undefined], 2]], ['select 1; set @a = 1', [[select1, rs2], [fields1, undefined], 2]], @@ -98,12 +98,12 @@ const tests = [ ['select * from no_rows; set @a = 1', [[[], rs3], [nr_fields, undefined], 2]], // select 0 rows + insert [ 'set @a = 1; select * from some_rows', - [[select3, rs3], [sr_fields, undefined], 2] + [[select3, rs3], [sr_fields, undefined], 2], ], // insert + select 3 rows [ 'select * from some_rows; set @a = 1', - [[select3, rs3], [sr_fields, undefined], 2] - ] // select 3 rows + insert + [[select3, rs3], [sr_fields, undefined], 2], + ], // select 3 rows + insert ]; function procedurise(sql) { @@ -112,12 +112,12 @@ function procedurise(sql) { 'CREATE PROCEDURE _as_sp_call()', 'BEGIN', `${sql};`, - 'END' + 'END', ].join('\n'); } function do_test(testIndex) { - const next = function() { + const next = function () { if (testIndex + 1 < tests.length) { do_test(testIndex + 1); } else { @@ -130,7 +130,7 @@ function do_test(testIndex) { const expectation = entry[1]; // prepared statements do not support multiple statements itself, we need to wrap quey in a stored procedure const sp = procedurise(sql); - mysql.query(sp, err => { + mysql.query(sp, (err) => { if (err) { throw err; } @@ -142,7 +142,7 @@ function do_test(testIndex) { throw err; } - const arrOrColumn = function(c) { + const arrOrColumn = function (c) { if (Array.isArray(c)) { return c.map(arrOrColumn); } diff --git a/test/integration/connection/test-binary-notnull-nulls.js b/test/integration/connection/test-binary-notnull-nulls.test.cjs similarity index 85% rename from test/integration/connection/test-binary-notnull-nulls.js rename to test/integration/connection/test-binary-notnull-nulls.test.cjs index a40838575d..b1c9078ba5 100644 --- a/test/integration/connection/test-binary-notnull-nulls.js +++ b/test/integration/connection/test-binary-notnull-nulls.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); -const common = require('../../common'); +const common = require('../../common.test.cjs'); const conn = common.createConnection(); // it's possible to receive null values for columns marked with NOT_NULL flag @@ -18,7 +18,7 @@ conn.query( ' `access_token` varchar(30) NOT NULL, ' + ' `refresh_token` tinytext NOT NULL, ' + ' PRIMARY KEY (`id`) ' + - ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8' + ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8', ); conn.query("INSERT INTO `tmp_account` VALUES ('1', 'xgredx', '', '', '')"); @@ -27,7 +27,7 @@ conn.query( ' `account` int(11) NOT NULL, ' + ' `flag` tinyint(3) NOT NULL, ' + ' PRIMARY KEY (`account`,`flag`) ' + - ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8' + ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8', ); conn.query("INSERT INTO `tmp_account_flags` VALUES ('1', '100')"); @@ -39,14 +39,14 @@ conn.query( ' `session` varchar(114) NOT NULL, ' + ' `time` int(11) NOT NULL, ' + ' PRIMARY KEY (`account`,`ip`) ' + - ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8' + ' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8', ); conn.query( - "INSERT INTO `tmp_account_session` VALUES ('1', '::1', '75efb145482ce22f4544390cad233c749c1b43e4', '1')" + "INSERT INTO `tmp_account_session` VALUES ('1', '::1', '75efb145482ce22f4544390cad233c749c1b43e4', '1')", ); -conn.connect(err => { +conn.connect((err) => { if (err) { console.error(err); return; @@ -67,6 +67,6 @@ conn.connect(err => { const valueIsNull = rows[0][fields[0].name] === null; assert(valueIsNull); conn.end(); - } + }, ); }); diff --git a/test/integration/connection/test-buffer-params.js b/test/integration/connection/test-buffer-params.test.cjs similarity index 78% rename from test/integration/connection/test-buffer-params.js rename to test/integration/connection/test-buffer-params.test.cjs index 8f3b7172f5..6db3d4fba7 100644 --- a/test/integration/connection/test-buffer-params.js +++ b/test/integration/connection/test-buffer-params.test.cjs @@ -1,28 +1,14 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; let rows1 = undefined; const buf = Buffer.from([ - 0x80, - 0x90, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 100, - 100, - 255, - 255 + 0x80, 0x90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100, 100, 255, 255, ]); connection.execute('SELECT HEX(?) as buf', [buf], (err, _rows) => { if (err) { diff --git a/test/integration/connection/test-change-user-multi-factor.js b/test/integration/connection/test-change-user-multi-factor.test.cjs similarity index 83% rename from test/integration/connection/test-change-user-multi-factor.js rename to test/integration/connection/test-change-user-multi-factor.test.cjs index 6a1e4de859..1d7a621a15 100644 --- a/test/integration/connection/test-change-user-multi-factor.js +++ b/test/integration/connection/test-change-user-multi-factor.test.cjs @@ -6,7 +6,7 @@ const mysql = require('../../../index.js'); const Command = require('../../../lib/commands/command.js'); const Packets = require('../../../lib/packets/index.js'); -const assert = require('assert'); +const { assert } = require('poku'); class TestChangeUserMultiFactor extends Command { constructor(args) { @@ -21,7 +21,7 @@ class TestChangeUserMultiFactor extends Command { serverVersion: 'node.js rocks', // the server should announce support for the // "MULTI_FACTOR_AUTHENTICATION" capability - capabilityFlags: 0xdfffffff + capabilityFlags: 0xdfffffff, }); this.serverHello = serverHelloPacket; serverHelloPacket.setScrambleData(() => { @@ -62,19 +62,22 @@ class TestChangeUserMultiFactor extends Command { } } -const server = mysql.createServer(conn => { +const server = mysql.createServer((conn) => { conn.serverConfig = {}; conn.serverConfig.encoding = 'cesu8'; conn.addCommand( - new TestChangeUserMultiFactor([{ - // already covered by test-auth-switch - pluginName: 'auth_test_plugin1', - pluginData: Buffer.from('foo') - }, { - // 2nd factor auth plugin - pluginName: 'auth_test_plugin2', - pluginData: Buffer.from('bar') - }]) + new TestChangeUserMultiFactor([ + { + // already covered by test-auth-switch + pluginName: 'auth_test_plugin1', + pluginData: Buffer.from('foo'), + }, + { + // 2nd factor auth plugin + pluginName: 'auth_test_plugin2', + pluginData: Buffer.from('bar'), + }, + ]), ); }); @@ -88,7 +91,7 @@ portfinder.getPort((_, port) => { const conn = mysql.createConnection({ port: port, authPlugins: { - auth_test_plugin1 (options) { + auth_test_plugin1(options) { return () => { if (options.connection.config.password !== password1) { return assert.fail('Incorrect authentication factor password.'); @@ -98,9 +101,9 @@ portfinder.getPort((_, port) => { completed.push(pluginName); return Buffer.from(pluginName); - } + }; }, - auth_test_plugin2 (options) { + auth_test_plugin2(options) { return () => { if (options.connection.config.password !== password2) { return assert.fail('Incorrect authentication factor password.'); @@ -110,20 +113,20 @@ portfinder.getPort((_, port) => { completed.push(pluginName); return Buffer.from(pluginName); - } - } - } + }; + }, + }, }); conn.on('connect', () => { - conn.changeUser({password1, password2}, () => { + conn.changeUser({ password1, password2 }, () => { assert.deepStrictEqual(completed, [ 'auth_test_plugin1', - 'auth_test_plugin2' + 'auth_test_plugin2', ]); conn.end(); server.close(); - }) + }); }); }); diff --git a/test/integration/connection/test-change-user-plugin-auth.js b/test/integration/connection/test-change-user-plugin-auth.test.cjs similarity index 80% rename from test/integration/connection/test-change-user-plugin-auth.js rename to test/integration/connection/test-change-user-plugin-auth.test.cjs index d23c590b8f..c76738aa86 100644 --- a/test/integration/connection/test-change-user-plugin-auth.js +++ b/test/integration/connection/test-change-user-plugin-auth.test.cjs @@ -5,18 +5,18 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const onlyUsername = function(name) { +const onlyUsername = function (name) { return name.substring(0, name.indexOf('@')); }; connection.query( - "CREATE USER IF NOT EXISTS 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'" + "CREATE USER IF NOT EXISTS 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'", ); connection.query( - "CREATE USER IF NOT EXISTS 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'" + "CREATE USER IF NOT EXISTS 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'", ); connection.query("GRANT ALL ON *.* TO 'changeuser1'@'%'"); connection.query("GRANT ALL ON *.* TO 'changeuser2'@'%'"); @@ -25,9 +25,9 @@ connection.query('FLUSH PRIVILEGES'); connection.changeUser( { user: 'changeuser1', - password: 'changeuser1pass' + password: 'changeuser1pass', }, - err => { + (err) => { assert.ifError(err); connection.query('select current_user()', (err, rows) => { assert.ifError(err); @@ -36,16 +36,16 @@ connection.changeUser( connection.changeUser( { user: 'changeuser2', - password: 'changeuser2pass' + password: 'changeuser2pass', }, - err => { + (err) => { assert.ifError(err); connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), - 'changeuser2' + 'changeuser2', ); connection.changeUser( @@ -54,23 +54,23 @@ connection.changeUser( password: 'changeuser1pass', passwordSha1: Buffer.from( 'f961d39c82138dcec42b8d0dcb3e40a14fb7e8cd', - 'hex' - ) // sha1(changeuser1pass) + 'hex', + ), // sha1(changeuser1pass) }, () => { connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), - 'changeuser1' + 'changeuser1', ); connection.end(); }); - } + }, ); }); - } + }, ); }); - } + }, ); diff --git a/test/integration/connection/test-change-user.js b/test/integration/connection/test-change-user.test.cjs similarity index 80% rename from test/integration/connection/test-change-user.js rename to test/integration/connection/test-change-user.test.cjs index d23c590b8f..c76738aa86 100644 --- a/test/integration/connection/test-change-user.js +++ b/test/integration/connection/test-change-user.test.cjs @@ -5,18 +5,18 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const onlyUsername = function(name) { +const onlyUsername = function (name) { return name.substring(0, name.indexOf('@')); }; connection.query( - "CREATE USER IF NOT EXISTS 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'" + "CREATE USER IF NOT EXISTS 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'", ); connection.query( - "CREATE USER IF NOT EXISTS 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'" + "CREATE USER IF NOT EXISTS 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'", ); connection.query("GRANT ALL ON *.* TO 'changeuser1'@'%'"); connection.query("GRANT ALL ON *.* TO 'changeuser2'@'%'"); @@ -25,9 +25,9 @@ connection.query('FLUSH PRIVILEGES'); connection.changeUser( { user: 'changeuser1', - password: 'changeuser1pass' + password: 'changeuser1pass', }, - err => { + (err) => { assert.ifError(err); connection.query('select current_user()', (err, rows) => { assert.ifError(err); @@ -36,16 +36,16 @@ connection.changeUser( connection.changeUser( { user: 'changeuser2', - password: 'changeuser2pass' + password: 'changeuser2pass', }, - err => { + (err) => { assert.ifError(err); connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), - 'changeuser2' + 'changeuser2', ); connection.changeUser( @@ -54,23 +54,23 @@ connection.changeUser( password: 'changeuser1pass', passwordSha1: Buffer.from( 'f961d39c82138dcec42b8d0dcb3e40a14fb7e8cd', - 'hex' - ) // sha1(changeuser1pass) + 'hex', + ), // sha1(changeuser1pass) }, () => { connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), - 'changeuser1' + 'changeuser1', ); connection.end(); }); - } + }, ); }); - } + }, ); }); - } + }, ); diff --git a/test/integration/connection/test-charset-encoding.js b/test/integration/connection/test-charset-encoding.test.cjs similarity index 83% rename from test/integration/connection/test-charset-encoding.js rename to test/integration/connection/test-charset-encoding.test.cjs index 1db90d24c1..df071ccebe 100644 --- a/test/integration/connection/test-charset-encoding.js +++ b/test/integration/connection/test-charset-encoding.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); // test data stores const testData = [ @@ -10,23 +10,23 @@ const testData = [ 'Experimental', 'परीक्षण', 'test тест テスト փորձաsրկում পরীক্ষা kiểm tra', - 'ტესტი પરીક્ષણ מבחן פּרובירן اختبار' + 'ტესტი પરીક્ષણ מבחן פּרובירן اختبار', ]; let resultData = null; // test inserting of non latin data if we are able to parse it -const testEncoding = function(err) { +const testEncoding = function (err) { assert.ifError(err); - testData.forEach(data => { + testData.forEach((data) => { connection.query( 'INSERT INTO `test-charset-encoding` (field) values(?)', [data], - err2 => { + (err2) => { assert.ifError(err2); - } + }, ); }); @@ -38,15 +38,15 @@ const testEncoding = function(err) { }; // init test sequence -(function() { +(function () { connection.query('DROP TABLE IF EXISTS `test-charset-encoding`', () => { connection.query( 'CREATE TABLE IF NOT EXISTS `test-charset-encoding` ' + '( `field` VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci)', - err => { + (err) => { assert.ifError(err); connection.query('DELETE from `test-charset-encoding`', testEncoding); - } + }, ); }); })(); diff --git a/test/integration/connection/test-connect-after-connection-error.js b/test/integration/connection/test-connect-after-connection-error.test.cjs similarity index 81% rename from test/integration/connection/test-connect-after-connection-error.js rename to test/integration/connection/test-connect-after-connection-error.test.cjs index 001a33fbc8..1b98d05749 100644 --- a/test/integration/connection/test-connect-after-connection-error.js +++ b/test/integration/connection/test-connect-after-connection-error.test.cjs @@ -1,7 +1,7 @@ 'use strict'; const mysql = require('../../../index.js'); -const assert = require('assert'); +const { assert } = require('poku'); const ERROR_TEXT = 'Connection lost: The server closed the connection.'; @@ -10,10 +10,10 @@ portfinder.getPort((err, port) => { const server = mysql.createServer(); let serverConnection; server.listen(port); - server.on('connection', conn => { + server.on('connection', (conn) => { conn.serverHandshake({ serverVersion: '5.6.10', - capabilityFlags: 2181036031 + capabilityFlags: 2181036031, }); serverConnection = conn; }); @@ -23,7 +23,7 @@ portfinder.getPort((err, port) => { port: port, user: 'testuser', database: 'testdatabase', - password: 'testpassword' + password: 'testpassword', }); clientConnection.on('connect', () => { @@ -31,7 +31,7 @@ portfinder.getPort((err, port) => { }); clientConnection.once('error', () => { - clientConnection.connect(err => { + clientConnection.connect((err) => { assert.equal(err.message, ERROR_TEXT); clientConnection.close(); server._server.close(); diff --git a/test/integration/connection/test-connect-after-connection.js b/test/integration/connection/test-connect-after-connection.test.cjs similarity index 79% rename from test/integration/connection/test-connect-after-connection.js rename to test/integration/connection/test-connect-after-connection.test.cjs index 4c40e52fa3..52e03f5fc1 100644 --- a/test/integration/connection/test-connect-after-connection.js +++ b/test/integration/connection/test-connect-after-connection.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let connection2; diff --git a/test/integration/connection/test-connect-connection-closed-error.js b/test/integration/connection/test-connect-connection-closed-error.test.cjs similarity index 78% rename from test/integration/connection/test-connect-connection-closed-error.js rename to test/integration/connection/test-connect-connection-closed-error.test.cjs index 84e7749db2..d6e33d71a4 100644 --- a/test/integration/connection/test-connect-connection-closed-error.js +++ b/test/integration/connection/test-connect-connection-closed-error.test.cjs @@ -1,7 +1,7 @@ 'use strict'; const mysql = require('../../../index.js'); -const assert = require('assert'); +const { assert } = require('poku'); const ERROR_TEXT = 'Connection lost: The server closed the connection.'; @@ -10,7 +10,7 @@ const portfinder = require('portfinder'); portfinder.getPort((err, port) => { const server = mysql.createServer(); server.listen(port); - server.on('connection', conn => { + server.on('connection', (conn) => { conn.close(); }); @@ -19,12 +19,11 @@ portfinder.getPort((err, port) => { port: port, user: 'testuser', database: 'testdatabase', - password: 'testpassword' + password: 'testpassword', }); - connection.query('select 1', err => { + connection.query('select 1', (err) => { assert.equal(err.message, ERROR_TEXT); server._server.close(); }); }); - diff --git a/test/integration/connection/test-connect-sha1.js b/test/integration/connection/test-connect-sha1.test.cjs similarity index 76% rename from test/integration/connection/test-connect-sha1.js rename to test/integration/connection/test-connect-sha1.test.cjs index 4372c6221e..8cd8c13306 100644 --- a/test/integration/connection/test-connect-sha1.js +++ b/test/integration/connection/test-connect-sha1.test.cjs @@ -2,7 +2,7 @@ const mysql = require('../../../index.js'); const auth = require('../../../lib/auth_41.js'); -const assert = require('assert'); +const { assert } = require('poku'); function authenticate(params, cb) { const doubleSha = auth.doubleSha1('testpassword'); @@ -10,7 +10,7 @@ function authenticate(params, cb) { params.authPluginData1, params.authPluginData2, params.authToken, - doubleSha + doubleSha, ); assert(isValid); cb(null); @@ -25,7 +25,7 @@ const portfinder = require('portfinder'); portfinder.getPort((err, port) => { const server = mysql.createServer(); server.listen(port); - server.on('connection', conn => { + server.on('connection', (conn) => { conn.serverHandshake({ protocolVersion: 10, serverVersion: 'node.js rocks', @@ -33,9 +33,9 @@ portfinder.getPort((err, port) => { statusFlags: 2, characterSet: 8, capabilityFlags: 0xffffff, - authCallback: authenticate + authCallback: authenticate, }); - conn.on('query', sql => { + conn.on('query', (sql) => { assert.equal(sql, 'select 1+1'); queryCalls++; conn.close(); @@ -46,24 +46,27 @@ portfinder.getPort((err, port) => { port: port, user: 'testuser', database: 'testdatabase', - passwordSha1: Buffer.from('8bb6118f8fd6935ad0876a3be34a717d32708ffd', 'hex') + passwordSha1: Buffer.from( + '8bb6118f8fd6935ad0876a3be34a717d32708ffd', + 'hex', + ), }); - connection.on('error', err => { + connection.on('error', (err) => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); }); - connection.query('select 1+1', err => { + connection.query('select 1+1', (err) => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); server._server.close(); }); - connection.query('select 1+2', err => { + connection.query('select 1+2', (err) => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); _1_2 = true; }); - connection.query('select 1+3', err => { + connection.query('select 1+3', (err) => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); _1_3 = true; }); diff --git a/test/integration/connection/test-connect-time-error.js b/test/integration/connection/test-connect-time-error.test.cjs similarity index 75% rename from test/integration/connection/test-connect-time-error.js rename to test/integration/connection/test-connect-time-error.test.cjs index ed3e64ef4b..4277658f05 100644 --- a/test/integration/connection/test-connect-time-error.js +++ b/test/integration/connection/test-connect-time-error.test.cjs @@ -1,7 +1,7 @@ 'use strict'; const mysql = require('../../../index.js'); -const assert = require('assert'); +const { assert } = require('poku'); const ERROR_TEXT = 'test error'; @@ -9,7 +9,7 @@ const portfinder = require('portfinder'); portfinder.getPort((err, port) => { const server = mysql.createServer(); server.listen(port); - server.on('connection', conn => { + server.on('connection', (conn) => { conn.writeError(new Error(ERROR_TEXT)); conn.close(); }); @@ -19,14 +19,14 @@ portfinder.getPort((err, port) => { port: port, user: 'testuser', database: 'testdatabase', - password: 'testpassword' + password: 'testpassword', }); - connection.query('select 1+1', err => { + connection.query('select 1+1', (err) => { assert.equal(err.message, ERROR_TEXT); }); - connection.query('select 1+2', err => { + connection.query('select 1+2', (err) => { assert.equal(err.message, ERROR_TEXT); connection.close(); server._server.close(); diff --git a/test/integration/connection/test-connect-with-uri.js b/test/integration/connection/test-connect-with-uri.test.cjs similarity index 70% rename from test/integration/connection/test-connect-with-uri.js rename to test/integration/connection/test-connect-with-uri.test.cjs index 358089b7df..98a74ef208 100644 --- a/test/integration/connection/test-connect-with-uri.js +++ b/test/integration/connection/test-connect-with-uri.test.cjs @@ -1,13 +1,15 @@ 'use strict'; if (process.env.MYSQL_CONNECTION_URL) { - console.log('skipping test when mysql server is configured using MYSQL_CONNECTION_URL'); + console.log( + 'skipping test when mysql server is configured using MYSQL_CONNECTION_URL', + ); process.exit(0); } -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnectionWithURI(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; let fields = undefined; diff --git a/test/integration/connection/test-connection-reset-while-closing.js b/test/integration/connection/test-connection-reset-while-closing.test.cjs similarity index 63% rename from test/integration/connection/test-connection-reset-while-closing.js rename to test/integration/connection/test-connection-reset-while-closing.test.cjs index 4a831e90a1..b3a5fecf6d 100644 --- a/test/integration/connection/test-connection-reset-while-closing.js +++ b/test/integration/connection/test-connection-reset-while-closing.test.cjs @@ -1,11 +1,13 @@ 'use strict'; +const common = require('../../common.test.cjs'); + +// Poku intentionally doesn't allow "rewriting" after uncaughtException const assert = require('assert'); -const common = require('../../common') const error = new Error('read ECONNRESET'); -error.code = 'ECONNRESET' -error.errno = -54 +error.code = 'ECONNRESET'; +error.errno = -54; error.syscall = 'read'; const connection = common.createConnection(); @@ -18,6 +20,6 @@ connection.query(`select 1 as "1"`, (err, rows) => { connection.stream.emit('error', error); }); -process.on('uncaughtException', err => { - assert.notEqual(err.code, 'ECONNRESET') +process.on('uncaughtException', (err) => { + assert.notEqual(err.code, 'ECONNRESET'); }); diff --git a/test/integration/connection/test-custom-date-parameter.js b/test/integration/connection/test-custom-date-parameter.test.cjs similarity index 84% rename from test/integration/connection/test-custom-date-parameter.js rename to test/integration/connection/test-custom-date-parameter.test.cjs index 4b356ce4c0..cc1042c6fa 100644 --- a/test/integration/connection/test-custom-date-parameter.js +++ b/test/integration/connection/test-custom-date-parameter.test.cjs @@ -1,13 +1,13 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ timezone: 'Z' }); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; // eslint-disable-next-line no-global-assign -Date = (function() { +Date = (function () { const NativeDate = Date; function CustomDate(str) { return new NativeDate(str); @@ -26,7 +26,7 @@ connection.execute( } rows = _rows; connection.end(); - } + }, ); process.on('exit', () => { diff --git a/test/integration/connection/test-date-parameter.js b/test/integration/connection/test-date-parameter.test.cjs similarity index 82% rename from test/integration/connection/test-date-parameter.js rename to test/integration/connection/test-date-parameter.test.cjs index 03808aafcc..74f4b57f07 100644 --- a/test/integration/connection/test-date-parameter.js +++ b/test/integration/connection/test-date-parameter.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ timezone: 'Z' }); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; @@ -16,7 +16,7 @@ connection.execute( } rows = _rows; connection.end(); - } + }, ); process.on('exit', () => { diff --git a/test/integration/connection/test-datetime.js b/test/integration/connection/test-datetime.test.cjs similarity index 94% rename from test/integration/connection/test-datetime.js rename to test/integration/connection/test-datetime.test.cjs index c664f26c54..5f428701a5 100644 --- a/test/integration/connection/test-datetime.js +++ b/test/integration/connection/test-datetime.test.cjs @@ -1,12 +1,12 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); const connection1 = common.createConnection({ dateStrings: true }); const connection2 = common.createConnection({ dateStrings: ['DATE'] }); const connectionZ = common.createConnection({ timezone: 'Z' }); const connection0930 = common.createConnection({ timezone: '+09:30' }); -const assert = require('assert'); +const { assert } = require('poku'); let rows, rowsZ, @@ -61,16 +61,16 @@ function formatUTCDateTime(d, precision) { } connection.query( - 'CREATE TEMPORARY TABLE t (d1 DATE, d2 DATETIME(3), d3 DATETIME(6))' + 'CREATE TEMPORARY TABLE t (d1 DATE, d2 DATETIME(3), d3 DATETIME(6))', ); connection.query('INSERT INTO t set d1=?, d2=?, d3=?', [ date, datetime, - datetime + datetime, ]); connection1.query( - 'CREATE TEMPORARY TABLE t (d1 DATE, d2 TIMESTAMP, d3 DATETIME, d4 DATETIME, d5 DATETIME(6), d6 DATETIME(3))' + 'CREATE TEMPORARY TABLE t (d1 DATE, d2 TIMESTAMP, d3 DATETIME, d4 DATETIME, d5 DATETIME(6), d6 DATETIME(3))', ); connection1.query('INSERT INTO t set d1=?, d2=?, d3=?, d4=?, d5=?, d6=?', [ date, @@ -78,11 +78,11 @@ connection1.query('INSERT INTO t set d1=?, d2=?, d3=?, d4=?, d5=?, d6=?', [ date2, date3, date4, - date5 + date5, ]); connection2.query( - 'CREATE TEMPORARY TABLE t (d1 DATE, d2 TIMESTAMP, d3 DATETIME, d4 DATETIME, d5 DATETIME(6), d6 DATETIME(3))' + 'CREATE TEMPORARY TABLE t (d1 DATE, d2 TIMESTAMP, d3 DATETIME, d4 DATETIME, d5 DATETIME(6), d6 DATETIME(3))', ); connection2.query('INSERT INTO t set d1=?, d2=?, d3=?, d4=?, d5=?, d6=?', [ date, @@ -90,27 +90,27 @@ connection2.query('INSERT INTO t set d1=?, d2=?, d3=?, d4=?, d5=?, d6=?', [ date2, date3, date4, - date5 + date5, ]); connectionZ.query( - 'CREATE TEMPORARY TABLE t (d1 DATE, d2 DATETIME(3), d3 DATETIME(6))' + 'CREATE TEMPORARY TABLE t (d1 DATE, d2 DATETIME(3), d3 DATETIME(6))', ); connectionZ.query("set time_zone = '+00:00'"); connectionZ.query('INSERT INTO t set d1=?, d2=?, d3=?', [ date, datetime, - datetime + datetime, ]); connection0930.query( - 'CREATE TEMPORARY TABLE t (d1 DATE, d2 DATETIME(3), d3 DATETIME(6))' + 'CREATE TEMPORARY TABLE t (d1 DATE, d2 DATETIME(3), d3 DATETIME(6))', ); connection0930.query("set time_zone = '+09:30'"); connection0930.query('INSERT INTO t set d1=?, d2=?, d3=?', [ date, datetime, - datetime + datetime, ]); const dateAsStringExpected = [ @@ -120,8 +120,8 @@ const dateAsStringExpected = [ d3: date2.substring(0, 19), d4: date3, d5: date4, - d6: date5 - } + d6: date5, + }, ]; connection.execute( @@ -132,7 +132,7 @@ connection.execute( throw err; } rows = _rows; - } + }, ); connectionZ.execute( @@ -143,7 +143,7 @@ connectionZ.execute( throw err; } rowsZ = _rows; - } + }, ); connection0930.execute( @@ -154,7 +154,7 @@ connection0930.execute( throw err; } rows0930 = _rows; - } + }, ); connection.query('select from_unixtime(631152000) t', (err, _rows) => { @@ -186,7 +186,7 @@ connection.query( } rows2 = _rows; connection.end(); - } + }, ); connectionZ.execute( @@ -197,7 +197,7 @@ connectionZ.execute( } rows3 = _rows; connectionZ.end(); - } + }, ); connection1.query('select * from t', (err, _rows) => { @@ -223,7 +223,7 @@ connection1.execute( } rows6 = _rows; connection1.end(); - } + }, ); connection2.execute('select * from t', (err, _rows) => { @@ -242,7 +242,7 @@ connection0930.execute( } rows7 = _rows; connection0930.end(); - } + }, ); process.on('exit', () => { @@ -275,21 +275,21 @@ process.on('exit', () => { assert.equal(rows1[0].t.constructor, Date); assert.equal( rows1[0].t.getTime(), - new Date('Mon Jan 01 1990 00:00:00 UTC').getTime() + new Date('Mon Jan 01 1990 00:00:00 UTC').getTime(), ); // UTC assert.equal(rows1Z[0].t.constructor, Date); assert.equal( rows1Z[0].t.getTime(), - new Date('Mon Jan 01 1990 00:00:00 UTC').getTime() + new Date('Mon Jan 01 1990 00:00:00 UTC').getTime(), ); // +09:30 assert.equal(rows10930[0].t.constructor, Date); assert.equal( rows10930[0].t.getTime(), - new Date('Mon Jan 01 1990 00:00:00 UTC').getTime() + new Date('Mon Jan 01 1990 00:00:00 UTC').getTime(), ); // local TZ diff --git a/test/integration/connection/test-decimals-as-numbers.js b/test/integration/connection/test-decimals-as-numbers.test.cjs similarity index 87% rename from test/integration/connection/test-decimals-as-numbers.js rename to test/integration/connection/test-decimals-as-numbers.test.cjs index 8a8c6b361c..38dd3a2c01 100644 --- a/test/integration/connection/test-decimals-as-numbers.js +++ b/test/integration/connection/test-decimals-as-numbers.test.cjs @@ -1,14 +1,14 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection1 = common.createConnection({ - decimalNumbers: false + decimalNumbers: false, }); const connection2 = common.createConnection({ - decimalNumbers: true + decimalNumbers: true, }); -const assert = require('assert'); +const { assert } = require('poku'); const largeDecimal = 900719.547409; const largeDecimalExpected = '900719.547409000000000000000000000000'; diff --git a/test/integration/connection/test-disconnects.js b/test/integration/connection/test-disconnects.test.cjs similarity index 86% rename from test/integration/connection/test-disconnects.js rename to test/integration/connection/test-disconnects.test.cjs index bee24bc842..db88d6398e 100644 --- a/test/integration/connection/test-disconnects.js +++ b/test/integration/connection/test-disconnects.test.cjs @@ -7,8 +7,8 @@ 'use strict'; -const common = require('../../common'); -const assert = require('assert'); +const common = require('../../common.test.cjs'); +const { assert } = require('poku'); let rows; let fields; @@ -24,7 +24,7 @@ const server = common.createServer( // server instance. host: 'localhost', port: server._port, - ssl: false + ssl: false, }); connection.query('SELECT 123', (err, _rows, _fields) => { if (err) { @@ -33,11 +33,11 @@ const server = common.createServer( rows = _rows; fields = _fields; - connection.on('error', _err => { + connection.on('error', (_err) => { err = _err; }); - connections.forEach(conn => { + connections.forEach((conn) => { conn.stream.end(); }); server._server.close(() => { @@ -46,11 +46,11 @@ const server = common.createServer( }); // TODO: test connection.end() etc where we expect disconnect to happen }, - conn => { + (conn) => { connections.push(conn); conn.on('query', () => { conn.writeTextResult( - [{ '1': '1' }], + [{ 1: '1' }], [ { catalog: 'def', @@ -64,12 +64,12 @@ const server = common.createServer( columnType: 8, type: 8, flags: 129, - decimals: 0 - } - ] + decimals: 0, + }, + ], ); }); - } + }, ); process.on('exit', () => { diff --git a/test/integration/connection/test-error-events.js b/test/integration/connection/test-error-events.test.cjs similarity index 76% rename from test/integration/connection/test-error-events.js rename to test/integration/connection/test-error-events.test.cjs index 87f0d1d64c..a889b8277e 100644 --- a/test/integration/connection/test-error-events.js +++ b/test/integration/connection/test-error-events.test.cjs @@ -1,18 +1,18 @@ 'use strict'; -const common = require('../../common'); -const assert = require('assert'); +const common = require('../../common.test.cjs'); +const { assert } = require('poku'); let callCount = 0; let exceptionCount = 0; -process.on('uncaughtException', err => { +process.on('uncaughtException', (err) => { assert.ifError(err); exceptionCount++; }); const connection1 = common.createConnection({ - password: 'lol' + password: 'lol', }); // error will NOT bubble up to process level if `on` is used @@ -21,7 +21,7 @@ connection1.on('error', () => { }); const connection2 = common.createConnection({ - password: 'lol' + password: 'lol', }); // error will bubble up to process level if `once` is used diff --git a/test/integration/connection/test-errors.js b/test/integration/connection/test-errors.test.cjs similarity index 89% rename from test/integration/connection/test-errors.js rename to test/integration/connection/test-errors.test.cjs index 35f6649a2a..68abc8e62a 100644 --- a/test/integration/connection/test-errors.js +++ b/test/integration/connection/test-errors.test.cjs @@ -6,9 +6,9 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let onExecuteResultError = undefined; let onQueryResultError = undefined; @@ -18,7 +18,7 @@ let onExecuteErrorEvent1 = undefined; let onQueryErrorEvent1 = undefined; connection - .execute('error in execute', [], err => { + .execute('error in execute', [], (err) => { assert.equal(err.errno, 1064); assert.equal(err.code, 'ER_PARSE_ERROR'); assert.equal(err.sql, 'error in execute'); @@ -30,7 +30,7 @@ connection onExecuteErrorEvent = true; }); connection - .query('error in query', [], err => { + .query('error in query', [], (err) => { assert.equal(err.errno, 1064); assert.equal(err.code, 'ER_PARSE_ERROR'); assert.equal(err.sql, 'error in query'); diff --git a/test/integration/connection/test-execute-and-unprepare.js b/test/integration/connection/test-execute-and-unprepare.test.cjs similarity index 68% rename from test/integration/connection/test-execute-and-unprepare.js rename to test/integration/connection/test-execute-and-unprepare.test.cjs index a5244d93fc..d03ed335b9 100644 --- a/test/integration/connection/test-execute-and-unprepare.js +++ b/test/integration/connection/test-execute-and-unprepare.test.cjs @@ -1,12 +1,12 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); const max = 500; function exec(i) { const query = `select 1+${i}`; - connection.execute(query, err => { + connection.execute(query, (err) => { connection.unprepare(query); if (err) { throw err; @@ -18,7 +18,7 @@ function exec(i) { } }); } -connection.query('SET GLOBAL max_prepared_stmt_count=10', err => { +connection.query('SET GLOBAL max_prepared_stmt_count=10', (err) => { if (err) { throw err; } diff --git a/test/integration/connection/test-execute-bind-boolean.js b/test/integration/connection/test-execute-bind-boolean.test.cjs similarity index 79% rename from test/integration/connection/test-execute-bind-boolean.js rename to test/integration/connection/test-execute-bind-boolean.test.cjs index 39ec561803..f42fa35d5f 100644 --- a/test/integration/connection/test-execute-bind-boolean.js +++ b/test/integration/connection/test-execute-bind-boolean.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows; connection.execute( @@ -14,7 +14,7 @@ connection.execute( } rows = _rows; connection.end(); - } + }, ); process.on('exit', () => { diff --git a/test/integration/connection/test-execute-bind-date.js b/test/integration/connection/test-execute-bind-date.js deleted file mode 100644 index 525a4b3290..0000000000 --- a/test/integration/connection/test-execute-bind-date.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -const common = require('../../common'); -const connection = common.createConnection(); -const assert = require('assert'); - -const date = new Date(2018, 2, 10, 15, 12, 34, 1234); - -let rows; -connection.execute('SELECT CAST(? AS DATETIME(6)) AS result', [date], (err, _rows) => { - if (err) { - throw err; - } - rows = _rows; - connection.end(); -}); - -process.on('exit', () => { - assert.deepEqual(rows, [{ result: date }]); -}); diff --git a/test/integration/connection/test-execute-bind-date.test.cjs b/test/integration/connection/test-execute-bind-date.test.cjs new file mode 100644 index 0000000000..f7eb0dbb83 --- /dev/null +++ b/test/integration/connection/test-execute-bind-date.test.cjs @@ -0,0 +1,24 @@ +'use strict'; + +const common = require('../../common.test.cjs'); +const connection = common.createConnection(); +const { assert } = require('poku'); + +const date = new Date(2018, 2, 10, 15, 12, 34, 1234); + +let rows; +connection.execute( + 'SELECT CAST(? AS DATETIME(6)) AS result', + [date], + (err, _rows) => { + if (err) { + throw err; + } + rows = _rows; + connection.end(); + }, +); + +process.on('exit', () => { + assert.deepEqual(rows, [{ result: date }]); +}); diff --git a/test/integration/connection/test-execute-bind-function.js b/test/integration/connection/test-execute-bind-function.test.cjs similarity index 67% rename from test/integration/connection/test-execute-bind-function.js rename to test/integration/connection/test-execute-bind-function.test.cjs index 2c057d528d..ef4ac2cad0 100644 --- a/test/integration/connection/test-execute-bind-function.js +++ b/test/integration/connection/test-execute-bind-function.test.cjs @@ -1,13 +1,13 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let error = null; try { - connection.execute('SELECT ? AS result', [function() {}], () => {}); + connection.execute('SELECT ? AS result', [function () {}], () => {}); } catch (err) { error = err; connection.end(); diff --git a/test/integration/connection/test-execute-bind-json.js b/test/integration/connection/test-execute-bind-json.test.cjs similarity index 84% rename from test/integration/connection/test-execute-bind-json.js rename to test/integration/connection/test-execute-bind-json.test.cjs index ea8dea1fb9..296dfefcc0 100644 --- a/test/integration/connection/test-execute-bind-json.js +++ b/test/integration/connection/test-execute-bind-json.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const table = 'jsontable'; const testJson = [{ a: 1, b: true, c: ['foo'] }]; @@ -10,7 +10,7 @@ const testJson = [{ a: 1, b: true, c: ['foo'] }]; let rows; connection.query(`CREATE TEMPORARY TABLE ${table} (data JSON)`); connection.query( - `INSERT INTO ${table} (data) VALUES ('${JSON.stringify(testJson)}')` + `INSERT INTO ${table} (data) VALUES ('${JSON.stringify(testJson)}')`, ); connection.execute(`SELECT * from ${table}`, (err, _rows) => { if (err) { diff --git a/test/integration/connection/test-execute-bind-null.js b/test/integration/connection/test-execute-bind-null.test.cjs similarity index 69% rename from test/integration/connection/test-execute-bind-null.js rename to test/integration/connection/test-execute-bind-null.test.cjs index 7af88b60fe..7ade3b828a 100644 --- a/test/integration/connection/test-execute-bind-null.js +++ b/test/integration/connection/test-execute-bind-null.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows; connection.execute( @@ -14,11 +14,11 @@ connection.execute( } rows = _rows; connection.end(); - } + }, ); process.on('exit', () => { assert.deepEqual(rows, [ - { firstValue: 'foo', nullValue: null, lastValue: 'bar' } + { firstValue: 'foo', nullValue: null, lastValue: 'bar' }, ]); }); diff --git a/test/integration/connection/test-execute-bind-number.js b/test/integration/connection/test-execute-bind-number.test.cjs similarity index 78% rename from test/integration/connection/test-execute-bind-number.js rename to test/integration/connection/test-execute-bind-number.test.cjs index d29dc1328e..ab52633be5 100644 --- a/test/integration/connection/test-execute-bind-number.js +++ b/test/integration/connection/test-execute-bind-number.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows; connection.execute( @@ -14,7 +14,7 @@ connection.execute( } rows = _rows; connection.end(); - } + }, ); process.on('exit', () => { @@ -23,7 +23,7 @@ process.on('exit', () => { zeroValue: 0, positiveValue: 123, negativeValue: -123, - decimalValue: 1.25 - } + decimalValue: 1.25, + }, ]); }); diff --git a/test/integration/connection/test-execute-bind-undefined.js b/test/integration/connection/test-execute-bind-undefined.test.cjs similarity index 82% rename from test/integration/connection/test-execute-bind-undefined.js rename to test/integration/connection/test-execute-bind-undefined.test.cjs index 0163b4722e..d177a94775 100644 --- a/test/integration/connection/test-execute-bind-undefined.js +++ b/test/integration/connection/test-execute-bind-undefined.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let error = null; diff --git a/test/integration/connection/test-execute-cached.js b/test/integration/connection/test-execute-cached.test.cjs similarity index 91% rename from test/integration/connection/test-execute-cached.js rename to test/integration/connection/test-execute-cached.test.cjs index 472ed687ae..bd73e9af1c 100644 --- a/test/integration/connection/test-execute-cached.js +++ b/test/integration/connection/test-execute-cached.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; let rows1 = undefined; diff --git a/test/integration/connection/test-execute-newdecimal.js b/test/integration/connection/test-execute-newdecimal.test.cjs similarity index 84% rename from test/integration/connection/test-execute-newdecimal.js rename to test/integration/connection/test-execute-newdecimal.test.cjs index 9ada5d042d..69b5007e71 100644 --- a/test/integration/connection/test-execute-newdecimal.js +++ b/test/integration/connection/test-execute-newdecimal.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); connection.query('CREATE TEMPORARY TABLE t (f DECIMAL(19,4))'); connection.query('INSERT INTO t VALUES(12345.67)'); diff --git a/test/integration/connection/test-execute-nocolumndef.js b/test/integration/connection/test-execute-nocolumndef.test.cjs similarity index 91% rename from test/integration/connection/test-execute-nocolumndef.js rename to test/integration/connection/test-execute-nocolumndef.test.cjs index ea810fb454..63116dc259 100644 --- a/test/integration/connection/test-execute-nocolumndef.js +++ b/test/integration/connection/test-execute-nocolumndef.test.cjs @@ -11,7 +11,7 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); const assert = require('assert-diff'); @@ -45,8 +45,8 @@ const expectedRows = [ rows: null, Extra: 'No tables used', partitions: null, - filtered: null - } + filtered: null, + }, ]; const expectedFields = [ @@ -61,7 +61,7 @@ const expectedFields = [ encoding: 'binary', type: 8, flags: 161, - decimals: 0 + decimals: 0, }, { catalog: 'def', @@ -74,7 +74,7 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 1, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -87,7 +87,7 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 0, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -100,7 +100,7 @@ const expectedFields = [ encoding: 'utf8', type: 250, flags: 0, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -113,7 +113,7 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 0, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -126,7 +126,7 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 0, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -139,7 +139,7 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 0, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -152,7 +152,7 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 0, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -165,7 +165,7 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 0, - decimals: 31 + decimals: 31, }, { catalog: 'def', @@ -178,7 +178,7 @@ const expectedFields = [ encoding: 'binary', type: 8, flags: 160, - decimals: 0 + decimals: 0, }, { catalog: 'def', @@ -191,7 +191,7 @@ const expectedFields = [ encoding: 'binary', type: 5, flags: 128, - decimals: 2 + decimals: 2, }, { catalog: 'def', @@ -204,8 +204,8 @@ const expectedFields = [ encoding: 'utf8', type: 253, flags: 1, - decimals: 31 - } + decimals: 31, + }, ]; process.on('exit', () => { @@ -217,7 +217,7 @@ process.on('exit', () => { assert.deepEqual( Object.keys(fi).sort(), - Object.keys(expectedFields[index]).sort() + Object.keys(expectedFields[index]).sort(), ); assert.deepEqual(expectedFields[index], fi); }); diff --git a/test/integration/connection/test-execute-null-bitmap.js b/test/integration/connection/test-execute-null-bitmap.test.cjs similarity index 72% rename from test/integration/connection/test-execute-null-bitmap.js rename to test/integration/connection/test-execute-null-bitmap.test.cjs index 75065eb005..acb2956c81 100644 --- a/test/integration/connection/test-execute-null-bitmap.js +++ b/test/integration/connection/test-execute-null-bitmap.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const params = [1, 2]; let query = 'select ? + ?'; @@ -11,7 +11,10 @@ function dotest() { connection.execute(`${query} as t`, params, (err, _rows) => { assert.equal(err, null); if (params.length < 50) { - assert.equal(_rows[0].t, params.reduce((x, y) => x + y)); + assert.equal( + _rows[0].t, + params.reduce((x, y) => x + y), + ); query += ' + ?'; params.push(params.length); dotest(); diff --git a/test/integration/connection/test-execute-order.js b/test/integration/connection/test-execute-order.test.cjs similarity index 58% rename from test/integration/connection/test-execute-order.js rename to test/integration/connection/test-execute-order.test.cjs index 2e187be4c2..a8de89cf30 100644 --- a/test/integration/connection/test-execute-order.js +++ b/test/integration/connection/test-execute-order.test.cjs @@ -1,19 +1,19 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const order = []; -connection.execute('select 1+2', err => { +connection.execute('select 1+2', (err) => { assert.ifError(err); order.push(0); }); -connection.execute('select 2+2', err => { +connection.execute('select 2+2', (err) => { assert.ifError(err); order.push(1); }); -connection.query('select 1+1', err => { +connection.query('select 1+1', (err) => { assert.ifError(err); order.push(2); connection.end(); diff --git a/test/integration/connection/test-execute-signed.js b/test/integration/connection/test-execute-signed.test.cjs similarity index 71% rename from test/integration/connection/test-execute-signed.js rename to test/integration/connection/test-execute-signed.test.cjs index 909a3887e7..6ee8112170 100644 --- a/test/integration/connection/test-execute-signed.js +++ b/test/integration/connection/test-execute-signed.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; @@ -13,16 +13,16 @@ connection.query( '`num` int(15),', '`l` long,', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query('insert into test_table(num,l) values(?, 3)', [1]); connection.query('insert into test_table(num,l) values(3-?, -10)', [5]); -connection.query('insert into test_table(num,l) values(4+?, 4000000-?)', [ - -5, - 8000000 -]); +connection.query( + 'insert into test_table(num,l) values(4+?, 4000000-?)', + [-5, 8000000], +); connection.execute('SELECT * from test_table', [], (err, _rows) => { if (err) { @@ -36,6 +36,6 @@ process.on('exit', () => { assert.deepEqual(rows, [ { id: 1, num: 1, l: 3 }, { id: 2, num: -2, l: -10 }, - { id: 3, num: -1, l: -4000000 } + { id: 3, num: -1, l: -4000000 }, ]); }); diff --git a/test/integration/connection/test-execute-type-casting.js b/test/integration/connection/test-execute-type-casting.test.cjs similarity index 85% rename from test/integration/connection/test-execute-type-casting.js rename to test/integration/connection/test-execute-type-casting.test.cjs index 02c416f790..3c61e1546a 100644 --- a/test/integration/connection/test-execute-type-casting.js +++ b/test/integration/connection/test-execute-type-casting.test.cjs @@ -1,14 +1,14 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); -connection.query('select 1', waitConnectErr => { +connection.query('select 1', (waitConnectErr) => { assert.ifError(waitConnectErr); - const tests = require('./type-casting-tests')(connection); + const tests = require('./type-casting-tests.test.cjs')(connection); const table = 'type_casting'; @@ -26,7 +26,7 @@ connection.query('select 1', waitConnectErr => { const createTable = [ `CREATE TEMPORARY TABLE \`${table}\` (`, - '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,' + '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', ] .concat(schema) .concat(['PRIMARY KEY (`id`)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8']) @@ -47,11 +47,11 @@ connection.query('select 1', waitConnectErr => { row = rows[0]; connection.end(); - } + }, ); process.on('exit', () => { - tests.forEach(test => { + tests.forEach((test) => { let expected = test.expect || test.insert; let got = row[test.columnName]; let message; @@ -70,7 +70,7 @@ connection.query('select 1', waitConnectErr => { if (test.deep) { message = `got: "${JSON.stringify(got)}" expected: "${JSON.stringify( - expected + expected, )}" test: ${test.type}`; assert.deepEqual(expected, got, message); } else { diff --git a/test/integration/connection/test-insert-bigint-big-number-strings.js b/test/integration/connection/test-insert-bigint-big-number-strings.test.cjs similarity index 91% rename from test/integration/connection/test-insert-bigint-big-number-strings.js rename to test/integration/connection/test-insert-bigint-big-number-strings.test.cjs index 9e4f51eb0b..1672e56e4f 100644 --- a/test/integration/connection/test-insert-bigint-big-number-strings.js +++ b/test/integration/connection/test-insert-bigint-big-number-strings.test.cjs @@ -1,11 +1,11 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ supportBigNumbers: true, - bigNumberStrings: true + bigNumberStrings: true, }); -const assert = require('assert'); +const { assert } = require('poku'); connection.query( [ @@ -13,8 +13,8 @@ connection.query( '`id` bigint NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query("INSERT INTO bigs SET title='test', id=123"); @@ -32,7 +32,7 @@ connection.query("INSERT INTO bigs SET title='test1'", (err, result) => { connection.query("INSERT INTO bigs SET title='test3'", (err, result) => { assert.strictEqual(result.insertId, '9007199254740993'); connection.query( - "INSERT INTO bigs SET title='test', id=90071992547409924" + "INSERT INTO bigs SET title='test', id=90071992547409924", ); connection.query("INSERT INTO bigs SET title='test4'", (err, result) => { assert.strictEqual(result.insertId, '90071992547409925'); diff --git a/test/integration/connection/test-insert-bigint.js b/test/integration/connection/test-insert-bigint.test.cjs similarity index 89% rename from test/integration/connection/test-insert-bigint.js rename to test/integration/connection/test-insert-bigint.test.cjs index b4e8f68a69..664dd7ea25 100644 --- a/test/integration/connection/test-insert-bigint.js +++ b/test/integration/connection/test-insert-bigint.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const Long = require('long'); connection.query( @@ -11,8 +11,8 @@ connection.query( '`id` bigint NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query("INSERT INTO bigs SET title='test', id=123"); @@ -30,21 +30,21 @@ connection.query("INSERT INTO bigs SET title='test1'", (err, result) => { connection.query("INSERT INTO bigs SET title='test3'", (err, result) => { assert.strictEqual( Long.fromString('9007199254740993').compare(result.insertId), - 0 + 0, ); connection.query( - "INSERT INTO bigs SET title='test', id=90071992547409924" + "INSERT INTO bigs SET title='test', id=90071992547409924", ); connection.query("INSERT INTO bigs SET title='test4'", (err, result) => { assert.strictEqual( Long.fromString('90071992547409925').compare(result.insertId), - 0 + 0, ); connection.query( { sql: 'select * from bigs', supportBigNumbers: true, - bigNumberString: false + bigNumberString: false, }, (err, result) => { assert.strictEqual(result[0].id, 123); @@ -56,7 +56,7 @@ connection.query("INSERT INTO bigs SET title='test1'", (err, result) => { assert.strictEqual(result[6].id, '90071992547409924'); assert.strictEqual(result[7].id, '90071992547409925'); connection.end(); - } + }, ); }); }); diff --git a/test/integration/connection/test-insert-json.js b/test/integration/connection/test-insert-json.test.cjs similarity index 76% rename from test/integration/connection/test-insert-json.js rename to test/integration/connection/test-insert-json.test.cjs index 85153da6fb..c51441cd6e 100644 --- a/test/integration/connection/test-insert-json.js +++ b/test/integration/connection/test-insert-json.test.cjs @@ -5,34 +5,32 @@ * issue#1924: https://github.com/sidorares/node-mysql2/issues/1924 */ -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let result; let errorCodeInvalidJSON; let errorNumInvalidJSON; - connection.query('CREATE TEMPORARY TABLE json_test (data JSON)'); -connection.query('INSERT INTO json_test VALUES (?)', ['{"k": "v"'], err => { +connection.query('INSERT INTO json_test VALUES (?)', ['{"k": "v"'], (err) => { errorCodeInvalidJSON = err.code; errorNumInvalidJSON = err.errno; }); -connection.query('INSERT INTO json_test VALUES (?)', ['{"k": "v"}'], err => { +connection.query('INSERT INTO json_test VALUES (?)', ['{"k": "v"}'], (err) => { if (err) throw err; }); -connection.query("SELECT * FROM json_test;", [], (err, res) => { +connection.query('SELECT * FROM json_test;', [], (err, res) => { if (err) throw err; result = res; connection.end(); -}) - +}); process.on('exit', () => { assert.equal(errorCodeInvalidJSON, 'ER_INVALID_JSON_TEXT'); assert.equal(errorNumInvalidJSON, 3140); - assert.equal(result[0].data.k, "v"); + assert.equal(result[0].data.k, 'v'); }); diff --git a/test/integration/connection/test-insert-large-blob.js b/test/integration/connection/test-insert-large-blob.test.cjs similarity index 90% rename from test/integration/connection/test-insert-large-blob.js rename to test/integration/connection/test-insert-large-blob.test.cjs index cfd7a8c368..fde63ff8e3 100644 --- a/test/integration/connection/test-insert-large-blob.js +++ b/test/integration/connection/test-insert-large-blob.test.cjs @@ -3,7 +3,7 @@ // intentionally disabled // eslint-disable-next-line no-constant-condition if (false) { - const common = require('../../common'); + const common = require('../../common.test.cjs'); const connection = common.createConnection(); /* @@ -15,7 +15,7 @@ if (false) { return; */ - const assert = require('assert'); + const { assert } = require('poku'); const table = 'insert_large_test'; const length = 35777416; @@ -37,7 +37,7 @@ if (false) { connection.query( `SET GLOBAL max_allowed_packet=${length * 2 + 2000}`, - err => { + (err) => { assert.ifError(err); connection.end(); const connection2 = common.createConnection(); @@ -47,8 +47,8 @@ if (false) { '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`content` longblob NOT NULL,', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection2.query( `INSERT INTO ${table} (content) VALUES(?)`, @@ -72,15 +72,15 @@ if (false) { assert.ifError(err); result4 = _result; connection2.end(); - } + }, ); - } + }, ); - } + }, ); - } + }, ); - } + }, ); process.on('exit', () => { diff --git a/test/integration/connection/test-insert-negative-ai.js b/test/integration/connection/test-insert-negative-ai.test.cjs similarity index 85% rename from test/integration/connection/test-insert-negative-ai.js rename to test/integration/connection/test-insert-negative-ai.test.cjs index 89ec40a4bb..587f02d65b 100644 --- a/test/integration/connection/test-insert-negative-ai.js +++ b/test/integration/connection/test-insert-negative-ai.test.cjs @@ -1,15 +1,15 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const testTable = 'neg-ai-test'; const testData = 'test negative ai'; let selectResult, insertResult; -const testNegativeAI = function(err) { +const testNegativeAI = function (err) { assert.ifError(err); // insert the negative AI connection.query( @@ -26,20 +26,20 @@ const testNegativeAI = function(err) { assert.ifError(err); selectResult = result_; connection.end(); - } + }, ); - } + }, ); }; -const prepareAndTest = function() { +const prepareAndTest = function () { connection.query( `CREATE TEMPORARY TABLE \`${testTable}\` (` + `\`id\` int(11) signed NOT NULL AUTO_INCREMENT,` + `\`title\` varchar(255),` + `PRIMARY KEY (\`id\`)` + `) ENGINE=InnoDB DEFAULT CHARSET=utf8`, - testNegativeAI + testNegativeAI, ); }; diff --git a/test/integration/connection/test-insert-results.js b/test/integration/connection/test-insert-results.test.cjs similarity index 58% rename from test/integration/connection/test-insert-results.js rename to test/integration/connection/test-insert-results.test.cjs index 422c2b81ea..9094c6110d 100644 --- a/test/integration/connection/test-insert-results.js +++ b/test/integration/connection/test-insert-results.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); // common.useTestDb(connection); @@ -15,27 +15,24 @@ connection.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); let result, result2; -connection.query( - `INSERT INTO ${table} SET title="${text}"`, - (err, _result) => { - if (err) { - throw err; - } - result = _result; - connection.query( - `SELECT * FROM ${table} WHERE id = ${result.insertId}`, - (err, _result2) => { - result2 = _result2; - connection.end(); - } - ); +connection.query(`INSERT INTO ${table} SET title="${text}"`, (err, _result) => { + if (err) { + throw err; } -); + result = _result; + connection.query( + `SELECT * FROM ${table} WHERE id = ${result.insertId}`, + (err, _result2) => { + result2 = _result2; + connection.end(); + }, + ); +}); process.on('exit', () => { assert.strictEqual(result.insertId, 1); diff --git a/test/integration/connection/test-invalid-date-result.js b/test/integration/connection/test-invalid-date-result.test.cjs similarity index 55% rename from test/integration/connection/test-invalid-date-result.js rename to test/integration/connection/test-invalid-date-result.test.cjs index bd03bed076..8204b82b2e 100644 --- a/test/integration/connection/test-invalid-date-result.js +++ b/test/integration/connection/test-invalid-date-result.test.cjs @@ -5,9 +5,9 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; @@ -15,31 +15,35 @@ let rows = undefined; // behaviour. const strictModes = ['NO_ZERO_DATE', 'NO_ZERO_IN_DATE']; -connection.query('SELECT variable_value as value FROM performance_schema.session_variables where variable_name = ?', ['sql_mode'], (err, _rows) => { - if (err) { - throw err; - } - - const deprecatedSqlMode = _rows[0].value - .split(',') - .filter(mode => strictModes.indexOf(mode) === -1) - .join(','); - - connection.query(`SET sql_mode=?`, [deprecatedSqlMode], err => { +connection.query( + 'SELECT variable_value as value FROM performance_schema.session_variables where variable_name = ?', + ['sql_mode'], + (err, _rows) => { if (err) { throw err; } - connection.execute('SELECT TIMESTAMP(0000-00-00) t', [], (err, _rows) => { + const deprecatedSqlMode = _rows[0].value + .split(',') + .filter((mode) => strictModes.indexOf(mode) === -1) + .join(','); + + connection.query(`SET sql_mode=?`, [deprecatedSqlMode], (err) => { if (err) { throw err; } - rows = _rows; - connection.end(); + connection.execute('SELECT TIMESTAMP(0000-00-00) t', [], (err, _rows) => { + if (err) { + throw err; + } + + rows = _rows; + connection.end(); + }); }); - }); -}); + }, +); function isInvalidTime(t) { return isNaN(t.getTime()); diff --git a/test/integration/connection/test-load-infile.js b/test/integration/connection/test-load-infile.test.cjs similarity index 86% rename from test/integration/connection/test-load-infile.js rename to test/integration/connection/test-load-infile.test.cjs index 7091a2a5a4..aaf298e527 100644 --- a/test/integration/connection/test-load-infile.js +++ b/test/integration/connection/test-load-infile.test.cjs @@ -5,9 +5,9 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const fs = require('fs'); const table = 'load_data_test'; @@ -18,8 +18,8 @@ connection.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); const path = './test/fixtures/data.csv'; @@ -32,14 +32,14 @@ connection.query( { sql, values: [path, ','], - infileStreamFactory: () => fs.createReadStream(path) + infileStreamFactory: () => fs.createReadStream(path), }, (err, _ok) => { if (err) { throw err; } ok = _ok; - } + }, ); let rows; @@ -61,7 +61,7 @@ connection.query(sql, [badPath, ','], (err, result) => { }); // test path mapping -const createMyStream = function() { +const createMyStream = function () { const Stream = require('stream').PassThrough; const myStream = new Stream(); setTimeout(() => { @@ -78,7 +78,7 @@ connection.query( { sql: sql, values: [badPath, ','], - infileStreamFactory: createMyStream + infileStreamFactory: createMyStream, }, (err, result) => { if (err) { @@ -86,7 +86,7 @@ connection.query( } streamResult = result; connection.end(); - } + }, ); process.on('exit', () => { @@ -97,7 +97,7 @@ process.on('exit', () => { assert.equal( loadErr.message, - `As a result of LOCAL INFILE command server wants to read /does_not_exist.csv file, but as of v2.0 you must provide streamFactory option returning ReadStream.` + `As a result of LOCAL INFILE command server wants to read /does_not_exist.csv file, but as of v2.0 you must provide streamFactory option returning ReadStream.`, ); assert.equal(loadResult.affectedRows, 0); diff --git a/test/integration/connection/test-multiple-results.js b/test/integration/connection/test-multiple-results.test.cjs similarity index 90% rename from test/integration/connection/test-multiple-results.js rename to test/integration/connection/test-multiple-results.test.cjs index 81ea4a7c26..9fb4652334 100644 --- a/test/integration/connection/test-multiple-results.js +++ b/test/integration/connection/test-multiple-results.test.cjs @@ -10,8 +10,8 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const mysql = require('../../common.js').createConnection({ - multipleStatements: true +const mysql = require('../../common.test.cjs').createConnection({ + multipleStatements: true, }); const assert = require('assert-diff'); mysql.query('CREATE TEMPORARY TABLE no_rows (test int)'); @@ -20,7 +20,7 @@ mysql.query('INSERT INTO some_rows values(0)'); mysql.query('INSERT INTO some_rows values(42)'); mysql.query('INSERT INTO some_rows values(314149)'); -const clone = function(obj) { +const clone = function (obj) { return JSON.parse(JSON.stringify(obj)); }; @@ -31,14 +31,14 @@ const rs1 = { serverStatus: 10, warningStatus: 0, info: '', - changedRows: 0 + changedRows: 0, }; const rs2 = clone(rs1); rs2.serverStatus = 2; const twoInsertResult = [[rs1, rs2], [undefined, undefined], 2]; -const select1 = [{ '1': '1' }]; -const select2 = [{ '2': '2' }]; +const select1 = [{ 1: '1' }]; +const select2 = [{ 2: '2' }]; const fields1 = [ { catalog: 'def', @@ -51,8 +51,8 @@ const fields1 = [ orgName: '', orgTable: '', schema: '', - table: '' - } + table: '', + }, ]; const nr_fields = [ { @@ -66,8 +66,8 @@ const nr_fields = [ orgName: 'test', orgTable: 'no_rows', schema: mysql.config.database, - table: 'no_rows' - } + table: 'no_rows', + }, ]; const sr_fields = clone(nr_fields); sr_fields[0].orgTable = 'some_rows'; @@ -81,11 +81,11 @@ const tests = [ ['select * from some_rows', [select3, sr_fields, 1]], // select 3 rows [ 'SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT; SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;', - twoInsertResult + twoInsertResult, ], [ '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;', - twoInsertResult + twoInsertResult, ], // issue #26 ['set @a = 1', [rs2, undefined, 1]], // one insert result ['set @a = 1; set @b = 2', twoInsertResult], @@ -97,12 +97,12 @@ const tests = [ ['select * from no_rows; set @a = 1', [[[], rs2], [nr_fields, undefined], 2]], // select 0 rows + insert [ 'set @a = 1; select * from some_rows', - [[rs1, select3], [undefined, sr_fields], 2] + [[rs1, select3], [undefined, sr_fields], 2], ], // insert + select 3 rows [ 'select * from some_rows; set @a = 1', - [[select3, rs2], [sr_fields, undefined], 2] - ] // select 3 rows + insert + [[select3, rs2], [sr_fields, undefined], 2], + ], // select 3 rows + insert ]; // TODO: tests with error in the query with different index @@ -120,9 +120,7 @@ function do_test(testIndex) { // empty select _numResults = 1; } else if (_rows.length > 0) { - if ( - _rows.constructor.name === 'Array' - ) { + if (_rows.constructor.name === 'Array') { _numResults = 1; } @@ -138,7 +136,7 @@ function do_test(testIndex) { console.log(err); process.exit(-1); } - const arrOrColumn = function(c) { + const arrOrColumn = function (c) { if (Array.isArray(c)) { return c.map(arrOrColumn); } @@ -195,7 +193,7 @@ function do_test(testIndex) { } else { assert.deepEqual( arrOrColumn(_columns[fieldIndex]), - arrOrColumn(fields) + arrOrColumn(fields), ); } } diff --git a/test/integration/connection/test-named-placeholders.js b/test/integration/connection/test-named-placeholders.test.cjs similarity index 77% rename from test/integration/connection/test-named-placeholders.js rename to test/integration/connection/test-named-placeholders.test.cjs index 4b83953591..41f966eb94 100644 --- a/test/integration/connection/test-named-placeholders.js +++ b/test/integration/connection/test-named-placeholders.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); connection.query( [ @@ -11,20 +11,20 @@ connection.query( '`num1` int(15),', '`num2` int(15),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query('insert into test_table(num1,num2) values(?, 3)', [1]); connection.query('insert into test_table(num1,num2) values(3-?, -10)', [5]); -connection.query('insert into test_table(num1,num2) values(4+?, 4000000-?)', [ - -5, - 8000000 -]); -connection.query('insert into test_table(num1,num2) values(?, ?)', [ - -5, - 8000000 -]); +connection.query( + 'insert into test_table(num1,num2) values(4+?, 4000000-?)', + [-5, 8000000], +); +connection.query( + 'insert into test_table(num1,num2) values(?, ?)', + [-5, 8000000], +); connection.config.namedPlaceholders = true; const cmd = connection.execute( @@ -35,7 +35,7 @@ const cmd = connection.execute( throw err; } assert.deepEqual(rows, [{ id: 4, num1: -5, num2: 8000000 }]); - } + }, ); assert.equal(cmd.sql, 'SELECT * from test_table where num1 < ? and num2 > ?'); assert.deepEqual(cmd.values, [2, 100]); @@ -55,11 +55,11 @@ const qCmd = connection.query( throw err; } assert.deepEqual(rows, [{ id: 4, num1: -5, num2: 8000000 }]); - } + }, ); assert.equal( qCmd.sql, - 'SELECT * from test_table where num1 < 2 and num2 > 100' + 'SELECT * from test_table where num1 < 2 and num2 > 100', ); assert.deepEqual(qCmd.values, [2, 100]); @@ -73,20 +73,20 @@ connection.query('SELECT :a + :a as sum', { a: 2 }, (err, rows) => { const namedSql = connection.format( 'SELECT * from test_table where num1 < :numParam and num2 > :lParam', - { lParam: 100, numParam: 2 } + { lParam: 100, numParam: 2 }, ); assert.equal( namedSql, - 'SELECT * from test_table where num1 < 2 and num2 > 100' + 'SELECT * from test_table where num1 < 2 and num2 > 100', ); const unnamedSql = connection.format( 'SELECT * from test_table where num1 < ? and num2 > ?', - [2, 100] + [2, 100], ); assert.equal( unnamedSql, - 'SELECT * from test_table where num1 < 2 and num2 > 100' + 'SELECT * from test_table where num1 < 2 and num2 > 100', ); const pool = common.createPool(); diff --git a/test/integration/connection/test-nested-tables-query.js b/test/integration/connection/test-nested-tables-query.test.cjs similarity index 86% rename from test/integration/connection/test-nested-tables-query.js rename to test/integration/connection/test-nested-tables-query.test.cjs index 400f4f1630..c940480512 100644 --- a/test/integration/connection/test-nested-tables-query.js +++ b/test/integration/connection/test-nested-tables-query.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); @@ -13,8 +13,8 @@ connection.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query( [ @@ -22,8 +22,8 @@ connection.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query(`INSERT INTO ${table} SET ?`, { title: 'test' }); @@ -31,24 +31,24 @@ connection.query(`INSERT INTO ${table}1 SET ?`, { title: 'test1' }); const options1 = { nestTables: true, - sql: `SELECT * FROM ${table}` + sql: `SELECT * FROM ${table}`, }; const options2 = { nestTables: '_', - sql: `SELECT * FROM ${table}` + sql: `SELECT * FROM ${table}`, }; const options3 = { rowsAsArray: true, - sql: `SELECT * FROM ${table}` + sql: `SELECT * FROM ${table}`, }; const options4 = { nestTables: true, - sql: `SELECT notNested.id, notNested.title, nested.title FROM ${table} notNested LEFT JOIN ${table}1 nested ON notNested.id = nested.id` -} + sql: `SELECT notNested.id, notNested.title, nested.title FROM ${table} notNested LEFT JOIN ${table}1 nested ON notNested.id = nested.id`, +}; const options5 = { nestTables: true, - sql: `SELECT notNested.id, notNested.title, nested2.title FROM ${table} notNested LEFT JOIN ${table}1 nested2 ON notNested.id = nested2.id` -} + sql: `SELECT notNested.id, notNested.title, nested2.title FROM ${table} notNested LEFT JOIN ${table}1 nested2 ON notNested.id = nested2.id`, +}; let rows1, rows2, rows3, rows4, rows5, rows1e, rows2e, rows3e; connection.query(options1, (err, _rows) => { @@ -131,22 +131,22 @@ process.on('exit', () => { assert.equal(rows4.length, 1); assert.deepEqual(rows4[0], { nested: { - title: 'test1' + title: 'test1', }, notNested: { id: 1, - title: 'test' - } + title: 'test', + }, }); assert.equal(rows5.length, 1); assert.deepEqual(rows5[0], { nested2: { - title: 'test1' + title: 'test1', }, notNested: { id: 1, - title: 'test' - } + title: 'test', + }, }); assert.deepEqual(rows1, rows1e); diff --git a/test/integration/connection/test-null-buffer.js b/test/integration/connection/test-null-buffer.test.cjs similarity index 89% rename from test/integration/connection/test-null-buffer.js rename to test/integration/connection/test-null-buffer.test.cjs index df3a155ed4..1901475e7d 100644 --- a/test/integration/connection/test-null-buffer.js +++ b/test/integration/connection/test-null-buffer.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rowsTextProtocol; let rowsBinaryProtocol; diff --git a/test/integration/connection/test-null-double.js b/test/integration/connection/test-null-double.test.cjs similarity index 84% rename from test/integration/connection/test-null-double.js rename to test/integration/connection/test-null-double.test.cjs index 6937311a43..1531fccb36 100644 --- a/test/integration/connection/test-null-double.js +++ b/test/integration/connection/test-null-double.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows; diff --git a/test/integration/connection/test-null-int.js b/test/integration/connection/test-null-int.test.cjs similarity index 84% rename from test/integration/connection/test-null-int.js rename to test/integration/connection/test-null-int.test.cjs index 6937311a43..1531fccb36 100644 --- a/test/integration/connection/test-null-int.js +++ b/test/integration/connection/test-null-int.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows; diff --git a/test/integration/connection/test-null.js b/test/integration/connection/test-null.test.cjs similarity index 84% rename from test/integration/connection/test-null.js rename to test/integration/connection/test-null.test.cjs index 62c73dcd00..2864283393 100644 --- a/test/integration/connection/test-null.js +++ b/test/integration/connection/test-null.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows, rows1; let fields1; @@ -25,7 +25,7 @@ connection.query('SELECT * from t', (err, _rows, _fields) => { }); process.on('exit', () => { - assert.deepEqual(rows, [{ 'cast_result': null }]); + assert.deepEqual(rows, [{ cast_result: null }]); // assert.equal(fields[0].columnType, 253); // depeding on the server type could be 253 or 3, disabling this check for now assert.deepEqual(rows1, [{ i: null }]); assert.equal(fields1[0].columnType, 3); diff --git a/test/integration/connection/test-parameters-questionmark.js b/test/integration/connection/test-parameters-questionmark.test.cjs similarity index 79% rename from test/integration/connection/test-parameters-questionmark.js rename to test/integration/connection/test-parameters-questionmark.test.cjs index e2efe4bc9f..6b623b5048 100644 --- a/test/integration/connection/test-parameters-questionmark.js +++ b/test/integration/connection/test-parameters-questionmark.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const common = require('../../common'); -const assert = require('assert'); +const common = require('../../common.test.cjs'); +const { assert } = require('poku'); const pool = common.createPool(); pool.config.connectionLimit = 1; @@ -12,13 +12,13 @@ pool.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`str` varchar(64),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); pool.query('insert into test_table(str) values(?)', ['abc?']); pool.query('UPDATE test_table SET str = ? WHERE id = ?', [ 'should not change ?', - 1 + 1, ]); pool.query('SELECT str FROM test_table WHERE id = ?', [1], (err, rows) => { pool.end(); diff --git a/test/integration/connection/test-prepare-and-close.js b/test/integration/connection/test-prepare-and-close.test.cjs similarity index 80% rename from test/integration/connection/test-prepare-and-close.js rename to test/integration/connection/test-prepare-and-close.test.cjs index d25f2e29b4..fbf6c9d54c 100644 --- a/test/integration/connection/test-prepare-and-close.js +++ b/test/integration/connection/test-prepare-and-close.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const max = 500; const start = process.hrtime(); @@ -26,7 +26,7 @@ function prepare(i) { assert(0, 'Error in prepare!'); }); } -connection.query('SET GLOBAL max_prepared_stmt_count=10', err => { +connection.query('SET GLOBAL max_prepared_stmt_count=10', (err) => { assert.ifError(err); prepare(1); }); diff --git a/test/integration/connection/test-prepare-simple.js b/test/integration/connection/test-prepare-simple.test.cjs similarity index 90% rename from test/integration/connection/test-prepare-simple.js rename to test/integration/connection/test-prepare-simple.test.cjs index 70199a61fc..4a7e4fbe9c 100644 --- a/test/integration/connection/test-prepare-simple.js +++ b/test/integration/connection/test-prepare-simple.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let _stmt1, _stmt2, _stmt3; const query1 = 'select 1 + ? + ? as test'; diff --git a/test/integration/connection/test-prepare-then-execute.js b/test/integration/connection/test-prepare-then-execute.test.cjs similarity index 87% rename from test/integration/connection/test-prepare-then-execute.js rename to test/integration/connection/test-prepare-then-execute.test.cjs index 4f50ba00b1..5d0973d8de 100644 --- a/test/integration/connection/test-prepare-then-execute.js +++ b/test/integration/connection/test-prepare-then-execute.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let _stmt = null; let _columns = null; diff --git a/test/integration/connection/test-protocol-errors.js b/test/integration/connection/test-protocol-errors.test.cjs similarity index 86% rename from test/integration/connection/test-protocol-errors.js rename to test/integration/connection/test-protocol-errors.test.cjs index 81a8c9c002..0d85838c46 100644 --- a/test/integration/connection/test-protocol-errors.js +++ b/test/integration/connection/test-protocol-errors.test.cjs @@ -7,8 +7,8 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); let fields, error; const query = 'SELECT 1'; @@ -23,7 +23,7 @@ const server = common.createServer( // server instance. host: 'localhost', port: server._port, - ssl: false + ssl: false, }); connection.query(query, (err, _rows, _fields) => { if (err) { @@ -33,17 +33,17 @@ const server = common.createServer( fields = _fields; }); - connection.on('error', err => { + connection.on('error', (err) => { error = err; if (server._server._handle) { server.close(); } }); }, - conn => { + (conn) => { conn.on('query', () => { conn.writeTextResult( - [{ '1': '1' }], + [{ 1: '1' }], [ { catalog: 'def', @@ -56,14 +56,14 @@ const server = common.createServer( columnLength: 1, columnType: 8, flags: 129, - decimals: 0 - } - ] + decimals: 0, + }, + ], ); // this is extra (incorrect) packet - client should emit error on receiving it conn.writeOk(); }); - } + }, ); process.on('exit', () => { @@ -71,7 +71,7 @@ process.on('exit', () => { assert.equal(fields[0].name, '1'); assert.equal( error.message, - 'Unexpected packet while no commands in the queue' + 'Unexpected packet while no commands in the queue', ); assert.equal(error.fatal, true); assert.equal(error.code, 'PROTOCOL_UNEXPECTED_PACKET'); diff --git a/test/integration/connection/test-query-timeout.js b/test/integration/connection/test-query-timeout.test.cjs similarity index 51% rename from test/integration/connection/test-query-timeout.js rename to test/integration/connection/test-query-timeout.test.cjs index ba5996dd81..8760be1cb7 100644 --- a/test/integration/connection/test-query-timeout.js +++ b/test/integration/connection/test-query-timeout.test.cjs @@ -1,13 +1,13 @@ 'use strict'; const portfinder = require('portfinder'); -const assert = require('assert'); -const common = require('../../common'); +const common = require('../../common.test.cjs'); const mysql = require('../../../index.js'); -const connection = common.createConnection({ debug: false }); +// Poku intentionally doesn't allow "rewriting" after uncaughtException +const assert = require('assert'); -console.log('test query timeout'); +const connection = common.createConnection({ debug: false }); connection.query({ sql: 'SELECT sleep(3) as a', timeout: 500 }, (err, res) => { assert.equal(res, null); @@ -24,22 +24,31 @@ connection.query('SELECT sleep(1) as a', (err, res) => { assert.deepEqual(res, [{ a: 0 }]); }); -connection.execute({ sql: 'SELECT sleep(3) as a', timeout: 500 }, (err, res) => { - assert.equal(res, null); - assert.ok(err); - assert.equal(err.code, 'PROTOCOL_SEQUENCE_TIMEOUT'); - assert.equal(err.message, 'Query inactivity timeout'); -}); +connection.execute( + { sql: 'SELECT sleep(3) as a', timeout: 500 }, + (err, res) => { + assert.equal(res, null); + assert.ok(err); + assert.equal(err.code, 'PROTOCOL_SEQUENCE_TIMEOUT'); + assert.equal(err.message, 'Query inactivity timeout'); + }, +); -connection.execute({ sql: 'SELECT sleep(1) as a', timeout: 5000 }, (err, res) => { - assert.deepEqual(res, [{ a: 0 }]); -}); +connection.execute( + { sql: 'SELECT sleep(1) as a', timeout: 5000 }, + (err, res) => { + assert.deepEqual(res, [{ a: 0 }]); + }, +); -connection.query({ sql: 'select 1 from non_existing_table', timeout: 500 }, (err, res) => { - assert.equal(res, null); - assert.ok(err); - assert.equal(err.code, 'ER_NO_SUCH_TABLE'); -}); +connection.query( + { sql: 'select 1 from non_existing_table', timeout: 500 }, + (err, res) => { + assert.equal(res, null); + assert.ok(err); + assert.equal(err.code, 'ER_NO_SUCH_TABLE'); + }, +); connection.execute('SELECT sleep(1) as a', (err, res) => { assert.deepEqual(res, [{ a: 0 }]); @@ -57,25 +66,31 @@ portfinder.getPort((err, port) => { }); server.listen(port); - const connectionTimeout = mysql.createConnection({ + const connectionTimeout = mysql.createConnection({ host: 'localhost', port: port, connectTimeout: 1000, }); // return connect timeout error first - connectionTimeout.query({ sql: 'SELECT sleep(3) as a', timeout: 50 }, (err, res) => { - console.log('ok'); - assert.equal(res, null); - assert.ok(err); - assert.equal(err.code, 'ETIMEDOUT'); - assert.equal(err.message, 'connect ETIMEDOUT'); - connectionTimeout.destroy(); - server._server.close(); - }); + connectionTimeout.query( + { sql: 'SELECT sleep(3) as a', timeout: 50 }, + (err, res) => { + console.log('ok'); + assert.equal(res, null); + assert.ok(err); + assert.equal(err.code, 'ETIMEDOUT'); + assert.equal(err.message, 'connect ETIMEDOUT'); + connectionTimeout.destroy(); + server._server.close(); + }, + ); }); -process.on('uncaughtException', err => { - assert.equal(err.message, 'Connection lost: The server closed the connection.'); +process.on('uncaughtException', (err) => { + assert.equal( + err.message, + 'Connection lost: The server closed the connection.', + ); assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); -}); \ No newline at end of file +}); diff --git a/test/integration/connection/test-query-zero.js b/test/integration/connection/test-query-zero.test.cjs similarity index 76% rename from test/integration/connection/test-query-zero.js rename to test/integration/connection/test-query-zero.test.cjs index 35cdc38499..63d7f10cf7 100644 --- a/test/integration/connection/test-query-zero.js +++ b/test/integration/connection/test-query-zero.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows; connection.query('SELECT ? AS result', 0, (err, _rows) => { diff --git a/test/integration/connection/test-quit.js b/test/integration/connection/test-quit.test.cjs similarity index 88% rename from test/integration/connection/test-quit.js rename to test/integration/connection/test-quit.test.cjs index af8ff83de5..6ad1c2861c 100644 --- a/test/integration/connection/test-quit.js +++ b/test/integration/connection/test-quit.test.cjs @@ -7,8 +7,8 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); let quitReceived = false; const queryCli = 'SELECT 1'; let queryServ; @@ -23,7 +23,7 @@ const server = common.createServer( // server instance. host: 'localhost', port: server._port, - ssl: false + ssl: false, }); connection.query(queryCli, (err, _rows, _fields) => { @@ -36,7 +36,7 @@ const server = common.createServer( connection.end(); }); }, - conn => { + (conn) => { conn.on('quit', () => { // COM_QUIT quitReceived = true; @@ -44,10 +44,10 @@ const server = common.createServer( server.close(); }); - conn.on('query', q => { + conn.on('query', (q) => { queryServ = q; conn.writeTextResult( - [{ '1': '1' }], + [{ 1: '1' }], [ { catalog: 'def', @@ -60,12 +60,12 @@ const server = common.createServer( columnLength: 1, columnType: 8, flags: 129, - decimals: 0 - } - ] + decimals: 0, + }, + ], ); }); - } + }, ); process.on('exit', () => { diff --git a/test/integration/connection/test-select-1.js b/test/integration/connection/test-select-1.test.cjs similarity index 80% rename from test/integration/connection/test-select-1.js rename to test/integration/connection/test-select-1.test.cjs index b70228c829..495f00041b 100644 --- a/test/integration/connection/test-select-1.js +++ b/test/integration/connection/test-select-1.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); connection.query('SELECT 1 as result', (err, rows, fields) => { @@ -14,7 +14,7 @@ connection.query('SELECT 1 as result', (err, rows, fields) => { assert.deepEqual(rows, [{ result: 1 }]); assert.equal(fields[0].name, 'result'); - connection.end(err => { + connection.end((err) => { assert.ifError(err); process.exit(0); }); diff --git a/test/integration/connection/test-select-empty-string.js b/test/integration/connection/test-select-empty-string.test.cjs similarity index 78% rename from test/integration/connection/test-select-empty-string.js rename to test/integration/connection/test-select-empty-string.test.cjs index 1672eb980d..3268d9deb1 100644 --- a/test/integration/connection/test-select-empty-string.js +++ b/test/integration/connection/test-select-empty-string.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows, fields; connection.query('SELECT ""', (err, _rows, _fields) => { diff --git a/test/integration/connection/test-select-json.js b/test/integration/connection/test-select-json.test.cjs similarity index 91% rename from test/integration/connection/test-select-json.js rename to test/integration/connection/test-select-json.test.cjs index 142f38bcd3..613a30d585 100644 --- a/test/integration/connection/test-select-json.js +++ b/test/integration/connection/test-select-json.test.cjs @@ -4,9 +4,9 @@ * Created by Alexander Panko on 2016.09.23 18:02 * issue#409: https://github.com/sidorares/node-mysql2/issues/409 */ -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let textFetchedRows = undefined; let binaryFetchedRows = undefined; diff --git a/test/integration/connection/test-select-negative.js b/test/integration/connection/test-select-negative.test.cjs similarity index 84% rename from test/integration/connection/test-select-negative.js rename to test/integration/connection/test-select-negative.test.cjs index a90d938474..4cc670655a 100644 --- a/test/integration/connection/test-select-negative.js +++ b/test/integration/connection/test-select-negative.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; let rows1 = undefined; diff --git a/test/integration/connection/test-select-ssl.js b/test/integration/connection/test-select-ssl.test.cjs similarity index 85% rename from test/integration/connection/test-select-ssl.js rename to test/integration/connection/test-select-ssl.test.cjs index 0b28282c15..a7e66a9841 100644 --- a/test/integration/connection/test-select-ssl.js +++ b/test/integration/connection/test-select-ssl.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); connection.query(`SHOW STATUS LIKE 'Ssl_cipher'`, (err, rows) => { @@ -20,7 +20,7 @@ connection.query(`SHOW STATUS LIKE 'Ssl_cipher'`, (err, rows) => { assert.deepEqual(rows, [{ Variable_name: 'Ssl_cipher', Value: '' }]); } - connection.end(err => { + connection.end((err) => { assert.ifError(err); process.exit(0); }); diff --git a/test/integration/connection/test-select-utf8.js b/test/integration/connection/test-select-utf8.test.cjs similarity index 80% rename from test/integration/connection/test-select-utf8.js rename to test/integration/connection/test-select-utf8.test.cjs index 7a7e9f8e77..9d1f15aed3 100644 --- a/test/integration/connection/test-select-utf8.js +++ b/test/integration/connection/test-select-utf8.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; const multibyteText = '本日は晴天なり'; diff --git a/test/integration/connection/test-server-listen.js b/test/integration/connection/test-server-listen.test.cjs similarity index 88% rename from test/integration/connection/test-server-listen.js rename to test/integration/connection/test-server-listen.test.cjs index 7a229dd717..08ef233af1 100644 --- a/test/integration/connection/test-server-listen.js +++ b/test/integration/connection/test-server-listen.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); const mysql = require('../../../index.js'); // Verifies that the Server.listen can be called with any combination of @@ -16,7 +16,7 @@ function testListen(argsDescription, listenCaller) { setTimeout(() => { assert.ok( listenCallbackFired, - `Callback for call with ${argsDescription} did not fire` + `Callback for call with ${argsDescription} did not fire`, ); server._server.close(); }, 100); diff --git a/test/integration/connection/test-signed-tinyint.js b/test/integration/connection/test-signed-tinyint.test.cjs similarity index 76% rename from test/integration/connection/test-signed-tinyint.js rename to test/integration/connection/test-signed-tinyint.test.cjs index 3a365b0456..b1cf8e28a7 100644 --- a/test/integration/connection/test-signed-tinyint.js +++ b/test/integration/connection/test-signed-tinyint.test.cjs @@ -1,13 +1,13 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows = undefined; connection.query( - 'CREATE TEMPORARY TABLE signed_ints (b11 tinyint NOT NULL, b12 tinyint NOT NULL, b21 smallint NOT NULL)' + 'CREATE TEMPORARY TABLE signed_ints (b11 tinyint NOT NULL, b12 tinyint NOT NULL, b21 smallint NOT NULL)', ); connection.query('INSERT INTO signed_ints values (-3, -120, 500)'); connection.query('INSERT INTO signed_ints values (3, -110, -500)'); @@ -23,6 +23,6 @@ connection.execute('SELECT * from signed_ints', [5], (err, _rows) => { process.on('exit', () => { assert.deepEqual(rows, [ { b11: -3, b12: -120, b21: 500 }, - { b11: 3, b12: -110, b21: -500 } + { b11: 3, b12: -110, b21: -500 }, ]); }); diff --git a/test/integration/connection/test-stream-errors.js b/test/integration/connection/test-stream-errors.test.cjs similarity index 87% rename from test/integration/connection/test-stream-errors.js rename to test/integration/connection/test-stream-errors.test.cjs index 7082b4f986..ddb73d2d22 100644 --- a/test/integration/connection/test-stream-errors.js +++ b/test/integration/connection/test-stream-errors.test.cjs @@ -7,8 +7,8 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); let clientConnection; const err = new Error('This socket has been ended by the other party'); @@ -26,9 +26,9 @@ const server = common.createServer( // server instance. host: 'localhost', port: server._port, - ssl: false + ssl: false, }); - clientConnection.query(query, err => { + clientConnection.query(query, (err) => { if (err && err.code === 'HANDSHAKE_NO_SSL_SUPPORT') { clientConnection.end(); } @@ -38,13 +38,13 @@ const server = common.createServer( receivedError2 = err; clientConnection.query( 'trying to enqueue command to a connection which is already in error state', - err1 => { + (err1) => { receivedError3 = err1; - } + }, ); }); }, - conn => { + (conn) => { conn.on('query', () => { conn.writeColumns([ { @@ -58,15 +58,15 @@ const server = common.createServer( columnLength: 1, columnType: 8, flags: 129, - decimals: 0 - } + decimals: 0, + }, ]); // emulate stream error here clientConnection.stream.emit('error', err); clientConnection.stream.end(); server.close(); }); - } + }, ); process.on('exit', () => { @@ -77,6 +77,6 @@ process.on('exit', () => { assert.equal(receivedError3.fatal, true); assert.equal( receivedError3.message, - "Can't add new command when connection is in closed state" + "Can't add new command when connection is in closed state", ); }); diff --git a/test/integration/connection/test-stream.js b/test/integration/connection/test-stream.test.cjs similarity index 86% rename from test/integration/connection/test-stream.js rename to test/integration/connection/test-stream.test.cjs index 3a2b32368f..a5943632e3 100644 --- a/test/integration/connection/test-stream.js +++ b/test/integration/connection/test-stream.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let rows; const rows1 = []; @@ -17,45 +17,45 @@ connection.query( '`title` varchar(255) DEFAULT NULL,', '`text` varchar(255) DEFAULT NULL,', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', ].join('\n'), - err => { + (err) => { if (err) { throw err; } - } + }, ); connection.execute( 'INSERT INTO announcements(title, text) VALUES(?, ?)', ['Есть место, где заканчивается тротуар', 'Расти борода, расти'], - err => { + (err) => { if (err) { throw err; } - } + }, ); connection.execute( 'INSERT INTO announcements(title, text) VALUES(?, ?)', [ 'Граждане Российской Федерации имеют право собираться мирно без оружия', - 'проводить собрания, митинги и демонстрации, шествия и пикетирование' + 'проводить собрания, митинги и демонстрации, шествия и пикетирование', ], - err => { + (err) => { if (err) { throw err; } - } + }, ); connection.execute('SELECT * FROM announcements', async (err, _rows) => { rows = _rows; const s1 = connection.query('SELECT * FROM announcements').stream(); - s1.on('data', row => { + s1.on('data', (row) => { rows1.push(row); }); s1.on('end', () => { const s2 = connection.execute('SELECT * FROM announcements').stream(); - s2.on('data', row => { + s2.on('data', (row) => { rows2.push(row); }); s2.on('end', () => { @@ -68,7 +68,7 @@ connection.execute('SELECT * FROM announcements', async (err, _rows) => { } const s4 = connection.query('SELECT * FROM announcements').stream(); for await (const row of s4) { - await new Promise(resolve => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 1000)); rows4.push(row); } }); diff --git a/test/integration/connection/test-then-on-query.js b/test/integration/connection/test-then-on-query.test.cjs similarity index 77% rename from test/integration/connection/test-then-on-query.js rename to test/integration/connection/test-then-on-query.test.cjs index 61dc7a3d90..7871889789 100644 --- a/test/integration/connection/test-then-on-query.js +++ b/test/integration/connection/test-then-on-query.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let error = true; diff --git a/test/integration/connection/test-timestamp.js b/test/integration/connection/test-timestamp.test.cjs similarity index 94% rename from test/integration/connection/test-timestamp.js rename to test/integration/connection/test-timestamp.test.cjs index b16deb286d..0e1424bcf8 100644 --- a/test/integration/connection/test-timestamp.js +++ b/test/integration/connection/test-timestamp.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); connection.query('SET SQL_MODE="ALLOW_INVALID_DATES";'); connection.query('CREATE TEMPORARY TABLE t (f TIMESTAMP)'); diff --git a/test/integration/connection/test-track-state-change.js b/test/integration/connection/test-track-state-change.test.cjs similarity index 84% rename from test/integration/connection/test-track-state-change.js rename to test/integration/connection/test-track-state-change.test.cjs index f30d59d066..5f18fa5c19 100644 --- a/test/integration/connection/test-track-state-change.js +++ b/test/integration/connection/test-track-state-change.test.cjs @@ -5,9 +5,9 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let result1, result2; @@ -26,7 +26,7 @@ process.on('exit', () => { assert.deepEqual(result1.stateChanges.systemVariables, { character_set_connection: 'koi8r', character_set_client: 'koi8r', - character_set_results: 'koi8r' + character_set_results: 'koi8r', }); assert.deepEqual(result2.stateChanges.schema, 'mysql'); }); diff --git a/test/integration/connection/test-transaction-commit.js b/test/integration/connection/test-transaction-commit.test.cjs similarity index 66% rename from test/integration/connection/test-transaction-commit.js rename to test/integration/connection/test-transaction-commit.test.cjs index eef9cc7d37..70c630b65b 100644 --- a/test/integration/connection/test-transaction-commit.js +++ b/test/integration/connection/test-transaction-commit.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); @@ -13,22 +13,22 @@ connection.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); -connection.beginTransaction(err => { +connection.beginTransaction((err) => { assert.ifError(err); const row = { id: 1, - title: 'Test row' + title: 'Test row', }; - connection.query(`INSERT INTO ${table} SET ?`, row, err => { + connection.query(`INSERT INTO ${table} SET ?`, row, (err) => { assert.ifError(err); - connection.commit(err => { + connection.commit((err) => { assert.ifError(err); connection.query(`SELECT * FROM ${table}`, (err, rows) => { diff --git a/test/integration/connection/test-transaction-rollback.js b/test/integration/connection/test-transaction-rollback.test.cjs similarity index 66% rename from test/integration/connection/test-transaction-rollback.js rename to test/integration/connection/test-transaction-rollback.test.cjs index 5eeb56d4dc..94f2653318 100644 --- a/test/integration/connection/test-transaction-rollback.js +++ b/test/integration/connection/test-transaction-rollback.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); @@ -13,22 +13,22 @@ connection.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`title` varchar(255),', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); -connection.beginTransaction(err => { +connection.beginTransaction((err) => { assert.ifError(err); const row = { id: 1, - title: 'Test row' + title: 'Test row', }; - connection.query(`INSERT INTO ${table} SET ?`, row, err => { + connection.query(`INSERT INTO ${table} SET ?`, row, (err) => { assert.ifError(err); - connection.rollback(err => { + connection.rollback((err) => { assert.ifError(err); connection.query(`SELECT * FROM ${table}`, (err, rows) => { diff --git a/test/integration/connection/test-type-cast-null-fields-execute.js b/test/integration/connection/test-type-cast-null-fields-execute.test.cjs similarity index 88% rename from test/integration/connection/test-type-cast-null-fields-execute.js rename to test/integration/connection/test-type-cast-null-fields-execute.test.cjs index d85ef34a7a..666411df07 100644 --- a/test/integration/connection/test-type-cast-null-fields-execute.js +++ b/test/integration/connection/test-type-cast-null-fields-execute.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); @@ -16,7 +16,7 @@ connection.execute( 'PRIMARY KEY (`id`)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8', ].join('\n'), - err => { + (err) => { if (err) throw err; }, ); @@ -24,7 +24,7 @@ connection.execute( connection.execute( `INSERT INTO ${table} (date, number) VALUES (?, ?)`, [null, null], - err => { + (err) => { if (err) throw err; }, ); diff --git a/test/integration/connection/test-type-cast-null-fields.js b/test/integration/connection/test-type-cast-null-fields.test.cjs similarity index 80% rename from test/integration/connection/test-type-cast-null-fields.js rename to test/integration/connection/test-type-cast-null-fields.test.cjs index daa7a1742b..214e964caa 100644 --- a/test/integration/connection/test-type-cast-null-fields.js +++ b/test/integration/connection/test-type-cast-null-fields.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); @@ -14,13 +14,13 @@ connection.query( '`date` DATETIME NULL,', '`number` INT NULL,', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query(`INSERT INTO ${table} SET ?`, { date: null, - number: null + number: null, }); let results; diff --git a/test/integration/connection/test-type-casting-execute.js b/test/integration/connection/test-type-casting-execute.test.cjs similarity index 91% rename from test/integration/connection/test-type-casting-execute.js rename to test/integration/connection/test-type-casting-execute.test.cjs index a1258f1d7a..01bba81d23 100644 --- a/test/integration/connection/test-type-casting-execute.js +++ b/test/integration/connection/test-type-casting-execute.test.cjs @@ -1,16 +1,16 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const driver = require('../../../index.js'); //needed to check driver.Types const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); -connection.execute('select 1', waitConnectErr => { +connection.execute('select 1', (waitConnectErr) => { assert.ifError(waitConnectErr); - const tests = require('./type-casting-tests')(connection); + const tests = require('./type-casting-tests.test.cjs')(connection); const table = 'type_casting'; @@ -55,7 +55,7 @@ connection.execute('select 1', waitConnectErr => { }); process.on('exit', () => { - tests.forEach(test => { + tests.forEach((test) => { // check that the column type matches the type name stored in driver.Types const columnType = fieldData[test.columnName]; assert.equal( diff --git a/test/integration/connection/test-type-casting.js b/test/integration/connection/test-type-casting.test.cjs similarity index 82% rename from test/integration/connection/test-type-casting.js rename to test/integration/connection/test-type-casting.test.cjs index e322743830..d410d76430 100644 --- a/test/integration/connection/test-type-casting.js +++ b/test/integration/connection/test-type-casting.test.cjs @@ -1,16 +1,16 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const driver = require('../../../index.js'); //needed to check driver.Types const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); common.useTestDb(connection); -connection.query('select 1', waitConnectErr => { +connection.query('select 1', (waitConnectErr) => { assert.ifError(waitConnectErr); - const tests = require('./type-casting-tests')(connection); + const tests = require('./type-casting-tests.test.cjs')(connection); const table = 'type_casting'; @@ -28,7 +28,7 @@ connection.query('select 1', waitConnectErr => { const createTable = [ `CREATE TEMPORARY TABLE \`${table}\` (`, - '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,' + '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', ] .concat(schema) .concat(['PRIMARY KEY (`id`)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8']) @@ -47,18 +47,22 @@ connection.query('select 1', waitConnectErr => { row = rows[0]; // build a fieldName: fieldType lookup table - fieldData = fields.reduce((a,v) => { + fieldData = fields.reduce((a, v) => { a[v['name']] = v['type']; return a; - }, {} ); + }, {}); connection.end(); }); process.on('exit', () => { - tests.forEach(test => { + tests.forEach((test) => { // check that the column type matches the type name stored in driver.Types const columnType = fieldData[test.columnName]; - assert.equal(test.columnType === driver.Types[columnType], true, test.columnName); + assert.equal( + test.columnType === driver.Types[columnType], + true, + test.columnName, + ); let expected = test.expect || test.insert; let got = row[test.columnName]; let message; @@ -77,7 +81,7 @@ connection.query('select 1', waitConnectErr => { if (test.deep) { message = `got: "${JSON.stringify(got)}" expected: "${JSON.stringify( - expected + expected, )}" test: ${test.type}`; assert.deepEqual(expected, got, message); } else { diff --git a/test/integration/connection/test-typecast-execute.js b/test/integration/connection/test-typecast-execute.test.cjs similarity index 97% rename from test/integration/connection/test-typecast-execute.js rename to test/integration/connection/test-typecast-execute.test.cjs index 431562e562..fb2c8939cc 100644 --- a/test/integration/connection/test-typecast-execute.js +++ b/test/integration/connection/test-typecast-execute.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); connection.execute('CREATE TEMPORARY TABLE json_test (json_test JSON)'); connection.execute('INSERT INTO json_test VALUES (?)', [ diff --git a/test/integration/connection/test-typecast-geometry-execute.js b/test/integration/connection/test-typecast-geometry-execute.test.cjs similarity index 83% rename from test/integration/connection/test-typecast-geometry-execute.js rename to test/integration/connection/test-typecast-geometry-execute.test.cjs index b63008b73d..8b7d97ba04 100644 --- a/test/integration/connection/test-typecast-geometry-execute.js +++ b/test/integration/connection/test-typecast-geometry-execute.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); connection.execute('select 1', () => { const serverVersion = connection._handshakePacket.serverVersion; @@ -13,33 +13,33 @@ connection.execute('select 1', () => { connection.execute( { sql: `select ${stPrefix}GeomFromText('POINT(11 0)') as foo`, - typeCast: function(field, next) { + typeCast: function (field, next) { if (field.type === 'GEOMETRY') { return field.geometry(); } return next(); - } + }, }, (err, res) => { assert.ifError(err); assert.deepEqual(res[0].foo, { x: 11, y: 0 }); - } + }, ); connection.execute( { sql: `select ${stPrefix}GeomFromText('POINT(11 0)') as foo`, - typeCast: function(field, next) { + typeCast: function (field, next) { if (field.type === 'GEOMETRY') { return field.buffer(); } return next(); - } + }, }, (err, res) => { assert.ifError(err); assert.equal(Buffer.isBuffer(res[0].foo), true); - } + }, ); connection.end(); diff --git a/test/integration/connection/test-typecast-geometry.js b/test/integration/connection/test-typecast-geometry.test.cjs similarity index 83% rename from test/integration/connection/test-typecast-geometry.js rename to test/integration/connection/test-typecast-geometry.test.cjs index 955e368b47..f3eb0ac648 100644 --- a/test/integration/connection/test-typecast-geometry.js +++ b/test/integration/connection/test-typecast-geometry.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); connection.query('select 1', () => { const serverVersion = connection._handshakePacket.serverVersion; @@ -13,33 +13,33 @@ connection.query('select 1', () => { connection.query( { sql: `select ${stPrefix}GeomFromText('POINT(11 0)') as foo`, - typeCast: function(field, next) { + typeCast: function (field, next) { if (field.type === 'GEOMETRY') { return field.geometry(); } return next(); - } + }, }, (err, res) => { assert.ifError(err); assert.deepEqual(res[0].foo, { x: 11, y: 0 }); - } + }, ); connection.query( { sql: `select ${stPrefix}GeomFromText('POINT(11 0)') as foo`, - typeCast: function(field, next) { + typeCast: function (field, next) { if (field.type === 'GEOMETRY') { return field.buffer(); } return next(); - } + }, }, (err, res) => { assert.ifError(err); assert.equal(Buffer.isBuffer(res[0].foo), true); - } + }, ); connection.end(); diff --git a/test/integration/connection/test-typecast-overwriting-execute.js b/test/integration/connection/test-typecast-overwriting-execute.test.cjs similarity index 90% rename from test/integration/connection/test-typecast-overwriting-execute.js rename to test/integration/connection/test-typecast-overwriting-execute.test.cjs index ac4c2a78ba..ad88d92849 100644 --- a/test/integration/connection/test-typecast-overwriting-execute.js +++ b/test/integration/connection/test-typecast-overwriting-execute.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ typeCast: function (field, next) { diff --git a/test/integration/connection/test-typecast-overwriting.js b/test/integration/connection/test-typecast-overwriting.test.cjs similarity index 90% rename from test/integration/connection/test-typecast-overwriting.js rename to test/integration/connection/test-typecast-overwriting.test.cjs index 474359727d..6054a71837 100644 --- a/test/integration/connection/test-typecast-overwriting.js +++ b/test/integration/connection/test-typecast-overwriting.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ typeCast: function (field, next) { diff --git a/test/integration/connection/test-typecast.js b/test/integration/connection/test-typecast.test.cjs similarity index 97% rename from test/integration/connection/test-typecast.js rename to test/integration/connection/test-typecast.test.cjs index ed12036ce9..585c72754b 100644 --- a/test/integration/connection/test-typecast.js +++ b/test/integration/connection/test-typecast.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); connection.query('CREATE TEMPORARY TABLE json_test (json_test JSON)'); connection.query( diff --git a/test/integration/connection/test-update-changed-rows.js b/test/integration/connection/test-update-changed-rows.test.cjs similarity index 91% rename from test/integration/connection/test-update-changed-rows.js rename to test/integration/connection/test-update-changed-rows.test.cjs index 4ea38b287f..55f668c961 100644 --- a/test/integration/connection/test-update-changed-rows.js +++ b/test/integration/connection/test-update-changed-rows.test.cjs @@ -7,15 +7,14 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } - /** * created at 2016.09.17 15:24:34 * * issue#288: https://github.com/sidorares/node-mysql2/issues/288 */ -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); let result1 = undefined; let result2 = undefined; @@ -27,8 +26,8 @@ connection.query( '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,', '`value` int(5) NOT NULL,', 'PRIMARY KEY (`id`)', - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' - ].join('\n') + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', + ].join('\n'), ); connection.query('insert into changed_rows(value) values(1)'); connection.query('insert into changed_rows(value) values(1)'); diff --git a/test/integration/connection/type-casting-tests.js b/test/integration/connection/type-casting-tests.test.cjs similarity index 61% rename from test/integration/connection/type-casting-tests.js rename to test/integration/connection/type-casting-tests.test.cjs index 62b7aead4c..0564759252 100644 --- a/test/integration/connection/type-casting-tests.js +++ b/test/integration/connection/type-casting-tests.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(connection) { +module.exports = function (connection) { const serverVersion = connection._handshakePacket.serverVersion; // mysql8 renamed some standard functions // see https://dev.mysql.com/doc/refman/8.0/en/gis-wkb-functions.html @@ -18,23 +18,63 @@ module.exports = function(connection) { { type: 'bigint', insert: 6, columnType: 'LONGLONG' }, { type: 'mediumint', insert: 7, columnType: 'INT24' }, { type: 'year', insert: 2012, columnType: 'YEAR' }, - { type: 'timestamp', insert: new Date('2012-05-12 11:00:23'), columnType: 'TIMESTAMP' }, - { type: 'datetime', insert: new Date('2012-05-12 12:00:23'), columnType: 'DATETIME' }, - { type: 'date', insert: new Date('2012-05-12 00:00:00'), columnType: 'DATE' }, + { + type: 'timestamp', + insert: new Date('2012-05-12 11:00:23'), + columnType: 'TIMESTAMP', + }, + { + type: 'datetime', + insert: new Date('2012-05-12 12:00:23'), + columnType: 'DATETIME', + }, + { + type: 'date', + insert: new Date('2012-05-12 00:00:00'), + columnType: 'DATE', + }, { type: 'time', insert: '13:13:23', columnType: 'TIME' }, { type: 'time', insert: '-13:13:23', columnType: 'TIME' }, { type: 'time', insert: '413:13:23', columnType: 'TIME' }, { type: 'time', insert: '-413:13:23', columnType: 'TIME' }, - { type: 'binary(4)', insert: Buffer.from([0, 1, 254, 255]), columnType: 'STRING' }, - { type: 'varbinary(4)', insert: Buffer.from([0, 1, 254, 255]), columnType: 'VAR_STRING' }, - { type: 'tinyblob', insert: Buffer.from([0, 1, 254, 255]), columnType: 'BLOB' }, - { type: 'mediumblob', insert: Buffer.from([0, 1, 254, 255]), columnType: 'BLOB' }, - { type: 'longblob', insert: Buffer.from([0, 1, 254, 255]), columnType: 'BLOB' }, + { + type: 'binary(4)', + insert: Buffer.from([0, 1, 254, 255]), + columnType: 'STRING', + }, + { + type: 'varbinary(4)', + insert: Buffer.from([0, 1, 254, 255]), + columnType: 'VAR_STRING', + }, + { + type: 'tinyblob', + insert: Buffer.from([0, 1, 254, 255]), + columnType: 'BLOB', + }, + { + type: 'mediumblob', + insert: Buffer.from([0, 1, 254, 255]), + columnType: 'BLOB', + }, + { + type: 'longblob', + insert: Buffer.from([0, 1, 254, 255]), + columnType: 'BLOB', + }, { type: 'blob', insert: Buffer.from([0, 1, 254, 255]), columnType: 'BLOB' }, - { type: 'bit(32)', insert: Buffer.from([0, 1, 254, 255]), columnType: 'BIT' }, + { + type: 'bit(32)', + insert: Buffer.from([0, 1, 254, 255]), + columnType: 'BIT', + }, { type: 'char(5)', insert: 'Hello', columnType: 'STRING' }, { type: 'varchar(5)', insert: 'Hello', columnType: 'VAR_STRING' }, - { type: 'varchar(3) character set utf8 collate utf8_bin', insert: 'bin', columnType: 'VAR_STRING' }, + { + type: 'varchar(3) character set utf8 collate utf8_bin', + insert: 'bin', + columnType: 'VAR_STRING', + }, { type: 'tinytext', insert: 'Hello World', columnType: 'BLOB' }, { type: 'mediumtext', insert: 'Hello World', columnType: 'BLOB' }, { type: 'longtext', insert: 'Hello World', columnType: 'BLOB' }, @@ -43,12 +83,12 @@ module.exports = function(connection) { type: 'point', insertRaw: 'POINT(1.2,-3.4)', expect: { x: 1.2, y: -3.4 }, - deep: true, - columnType: 'GEOMETRY' + deep: true, + columnType: 'GEOMETRY', }, { type: 'point', - insertRaw: (function() { + insertRaw: (function () { const buffer = Buffer.alloc(21); buffer.writeUInt8(1, 0); buffer.writeUInt32LE(1, 1); @@ -57,16 +97,26 @@ module.exports = function(connection) { return `${stPrefix}GeomFromWKB(${connection.escape(buffer)})`; })(), expect: { x: -5.6, y: 10.23 }, - deep: true, - columnType: 'GEOMETRY' + deep: true, + columnType: 'GEOMETRY', + }, + { + type: 'point', + insertRaw: '', + insert: null, + expect: null, + columnType: 'GEOMETRY', }, - { type: 'point', insertRaw: '', insert: null, expect: null, columnType: 'GEOMETRY' }, { type: 'linestring', insertRaw: 'LINESTRING(POINT(1.2,-3.4),POINT(-5.6,10.23),POINT(0.2,0.7))', - expect: [{ x: 1.2, y: -3.4 }, { x: -5.6, y: 10.23 }, { x: 0.2, y: 0.7 }], - deep: true, - columnType: 'GEOMETRY' + expect: [ + { x: 1.2, y: -3.4 }, + { x: -5.6, y: 10.23 }, + { x: 0.2, y: 0.7 }, + ], + deep: true, + columnType: 'GEOMETRY', }, { type: 'polygon', @@ -77,42 +127,52 @@ module.exports = function(connection) { { x: 10, y: 0 }, { x: 10, y: 10 }, { x: 0, y: 10 }, - { x: 0, y: 0 } + { x: 0, y: 0 }, ], [ { x: 5, y: 5 }, { x: 7, y: 5 }, { x: 7, y: 7 }, { x: 5, y: 7 }, - { x: 5, y: 5 } - ] + { x: 5, y: 5 }, + ], ], - deep: true, - columnType: 'GEOMETRY' + deep: true, + columnType: 'GEOMETRY', }, { type: 'geometry', insertRaw: 'POINT(1.2,-3.4)', expect: { x: 1.2, y: -3.4 }, - deep: true, - columnType: 'GEOMETRY' + deep: true, + columnType: 'GEOMETRY', }, { type: 'multipoint', insertRaw: `${stPrefix}GeomFromText('MULTIPOINT(0 0, 20 20, 60 60)')`, - expect: [{ x: 0, y: 0 }, { x: 20, y: 20 }, { x: 60, y: 60 }], - deep: true, - columnType: 'GEOMETRY' + expect: [ + { x: 0, y: 0 }, + { x: 20, y: 20 }, + { x: 60, y: 60 }, + ], + deep: true, + columnType: 'GEOMETRY', }, { type: 'multilinestring', insertRaw: `${stPrefix}GeomFromText('MULTILINESTRING((10 10, 20 20), (15 15, 30 15))')`, expect: [ - [{ x: 10, y: 10 }, { x: 20, y: 20 }], - [{ x: 15, y: 15 }, { x: 30, y: 15 }] + [ + { x: 10, y: 10 }, + { x: 20, y: 20 }, + ], + [ + { x: 15, y: 15 }, + { x: 30, y: 15 }, + ], ], - deep: true, - columnType: 'GEOMETRY' + deep: true, + columnType: 'GEOMETRY', }, { type: 'multipolygon', @@ -124,8 +184,8 @@ module.exports = function(connection) { { x: 10, y: 0 }, { x: 10, y: 10 }, { x: 0, y: 10 }, - { x: 0, y: 0 } - ] + { x: 0, y: 0 }, + ], ], [ [ @@ -133,12 +193,12 @@ module.exports = function(connection) { { x: 7, y: 5 }, { x: 7, y: 7 }, { x: 5, y: 7 }, - { x: 5, y: 5 } - ] - ] + { x: 5, y: 5 }, + ], + ], ], - deep: true, - columnType: 'GEOMETRY' + deep: true, + columnType: 'GEOMETRY', }, { type: 'geometrycollection', @@ -146,10 +206,13 @@ module.exports = function(connection) { expect: [ { x: 11, y: 10 }, { x: 31, y: 30 }, - [{ x: 15, y: 15 }, { x: 20, y: 20 }] + [ + { x: 15, y: 15 }, + { x: 20, y: 20 }, + ], ], - deep: true, - columnType: 'GEOMETRY' - } + deep: true, + columnType: 'GEOMETRY', + }, ]; }; diff --git a/test/integration/promise-wrappers/test-async-stack.js b/test/integration/promise-wrappers/test-async-stack.test.cjs similarity index 88% rename from test/integration/promise-wrappers/test-async-stack.js rename to test/integration/promise-wrappers/test-async-stack.test.cjs index 7398406f0b..4c7e1a6856 100644 --- a/test/integration/promise-wrappers/test-async-stack.js +++ b/test/integration/promise-wrappers/test-async-stack.test.cjs @@ -1,10 +1,10 @@ 'use strict'; -const config = require('../../common.js').config; -const assert = require('assert'); +const config = require('../../common.test.cjs').config; +const { assert } = require('poku'); const ErrorStackParser = require('error-stack-parser'); -const createConnection = async function(args) { +const createConnection = async function (args) { const connect = require('../../../promise.js').createConnection; if (!args && process.env.MYSQL_CONNECTION_URL) { return connect({ uri: process.env.MYSQL_CONNECTION_URL }); @@ -38,7 +38,7 @@ async function test() { } } - test1().catch(err => { + test1().catch((err) => { const stack = ErrorStackParser.parse(err); const stackExpected = ErrorStackParser.parse(e1); assert(stack[2].getLineNumber() === stackExpected[0].getLineNumber() + 2); @@ -46,4 +46,4 @@ async function test() { }); } -test(); \ No newline at end of file +test(); diff --git a/test/integration/promise-wrappers/test-promise-wrappers.js b/test/integration/promise-wrappers/test-promise-wrappers.test.cjs similarity index 84% rename from test/integration/promise-wrappers/test-promise-wrappers.js rename to test/integration/promise-wrappers/test-promise-wrappers.test.cjs index 6a1fc17448..6f3a2b1f45 100644 --- a/test/integration/promise-wrappers/test-promise-wrappers.js +++ b/test/integration/promise-wrappers/test-promise-wrappers.test.cjs @@ -5,9 +5,9 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const config = require('../../common.js').config; +const config = require('../../common.test.cjs').config; -const assert = require('assert'); +const { assert } = require('poku'); const createConnection = require('../../../promise.js').createConnection; const createPool = require('../../../promise.js').createPool; @@ -28,22 +28,22 @@ let doneChangeUser = false; function testBasic() { let connResolved; createConnection(config) - .then(conn => { + .then((conn) => { connResolved = conn; return conn.query('select 1+2 as ttt'); }) - .then(result1 => { + .then((result1) => { assert.equal(result1[0][0].ttt, 3); return connResolved.query('select 2+2 as qqq'); }) - .then(result2 => { + .then((result2) => { assert.equal(result2[0][0].qqq, 4); return connResolved.end(); }) .then(() => { doneCalled = true; }) - .catch(err => { + .catch((err) => { throw err; }); } @@ -53,15 +53,15 @@ function testErrors() { const connPromise = createConnection(config); connPromise - .then(conn => { + .then((conn) => { connResolved = conn; return conn.query('select 1+2 as ttt'); }) - .then(result1 => { + .then((result1) => { assert.equal(result1[0][0].ttt, 3); return connResolved.query('bad sql'); }) - .then(result2 => { + .then((result2) => { assert.equal(result2[0][0].ttt, 3); return connResolved.query('select 2+2 as qqq'); }) @@ -78,25 +78,25 @@ function testErrors() { function testObjParams() { let connResolved; createConnection(config) - .then(conn => { + .then((conn) => { connResolved = conn; return conn.query({ sql: 'select ?-? as ttt', - values: [5, 2] + values: [5, 2], }); }) - .then(result1 => { + .then((result1) => { assert.equal(result1[0][0].ttt, 3); return connResolved.execute({ sql: 'select ?-? as ttt', - values: [8, 5] + values: [8, 5], }); }) - .then(result2 => { + .then((result2) => { assert.equal(result2[0][0].ttt, 3); return connResolved.end(); }) - .catch(err => { + .catch((err) => { console.log(err); }); } @@ -104,23 +104,23 @@ function testObjParams() { function testPrepared() { let connResolved; createConnection(config) - .then(conn => { + .then((conn) => { connResolved = conn; return conn.prepare('select ?-? as ttt, ? as uuu'); }) - .then(statement => statement.execute([11, 3, 'test'])) - .then(result => { + .then((statement) => statement.execute([11, 3, 'test'])) + .then((result) => { assert.equal(result[0][0].ttt, 8); assert.equal(result[0][0].uuu, 'test'); return connResolved.end(); }) - .catch(err => { + .catch((err) => { console.log(err); if (connResolved) { connResolved.end(); } else { console.log( - 'Warning: promise rejected before executing prepared statement' + 'Warning: promise rejected before executing prepared statement', ); } }); @@ -131,7 +131,7 @@ function testPrepared() { function testEventsConnect() { let connResolved; createConnection(config) - .then(conn => { + .then((conn) => { connResolved = conn; let events = 0; @@ -140,35 +140,35 @@ function testEventsConnect() { drain: 0, connect: 0, enqueue: 0, - end: 0 + end: 0, }; for (const eventName in expectedListeners) { assert.equal( conn.connection.listenerCount(eventName), expectedListeners[eventName], - eventName + eventName, ); } /* eslint-disable no-invalid-this */ conn - .once('error', function() { + .once('error', function () { assert.equal(this, conn); ++events; }) - .once('drain', function() { + .once('drain', function () { assert.equal(this, conn); ++events; }) - .once('connect', function() { + .once('connect', function () { assert.equal(this, conn); ++events; }) - .once('enqueue', function() { + .once('enqueue', function () { assert.equal(this, conn); ++events; }) - .once('end', function() { + .once('end', function () { assert.equal(this, conn); ++events; @@ -187,19 +187,19 @@ function testEventsConnect() { assert.equal( conn.connection.listenerCount(eventName), expectedListeners[eventName], - eventName + eventName, ); } conn.end(); }) - .catch(err => { + .catch((err) => { console.log(err); if (connResolved) { connResolved.end(); } else { console.log( - 'Warning: promise rejected before executing prepared statement' + 'Warning: promise rejected before executing prepared statement', ); } }); @@ -210,27 +210,27 @@ function testBasicPool() { const promiseConn = pool.getConnection(); promiseConn - .then(connResolved => { + .then((connResolved) => { pool.releaseConnection(connResolved); }) - .catch(err => { + .catch((err) => { throw err; }); pool .query('select 1+2 as ttt') - .then(result1 => { + .then((result1) => { assert.equal(result1[0][0].ttt, 3); return pool.query('select 2+2 as qqq'); }) - .then(result2 => { + .then((result2) => { assert.equal(result2[0][0].qqq, 4); return pool.end(); }) .then(() => { doneCalledPool = true; }) - .catch(err => { + .catch((err) => { throw err; }); } @@ -239,11 +239,11 @@ function testErrorsPool() { const pool = createPool(config); pool .query('select 1+2 as ttt') - .then(result1 => { + .then((result1) => { assert.equal(result1[0][0].ttt, 3); return pool.query('bad sql'); }) - .then(result2 => { + .then((result2) => { assert.equal(result2[0][0].ttt, 3); return pool.query('select 2+2 as qqq'); }) @@ -258,20 +258,20 @@ function testObjParamsPool() { pool .query({ sql: 'select ?-? as ttt', - values: [5, 2] + values: [5, 2], }) - .then(result1 => { + .then((result1) => { assert.equal(result1[0][0].ttt, 3); return pool.execute({ sql: 'select ?-? as ttt', - values: [8, 5] + values: [8, 5], }); }) - .then(result2 => { + .then((result2) => { assert.equal(result2[0][0].ttt, 3); return pool.end(); }) - .catch(err => { + .catch((err) => { console.log(err); }); } @@ -279,7 +279,7 @@ function testPromiseLibrary() { const pool = createPool(config); let promise = pool.execute({ sql: 'select ?-? as ttt', - values: [8, 5] + values: [8, 5], }); promise .then(() => { @@ -289,7 +289,7 @@ function testPromiseLibrary() { promise = pool.end(); assert.ok(promise instanceof pool.Promise); }) - .catch(err => { + .catch((err) => { console.log(err); }); } @@ -302,31 +302,31 @@ function testEventsPool() { acquire: 0, connection: 0, enqueue: 0, - release: 0 + release: 0, }; for (const eventName in expectedListeners) { assert.equal( pool.pool.listenerCount(eventName), expectedListeners[eventName], - eventName + eventName, ); } /* eslint-disable no-invalid-this */ pool - .once('acquire', function() { + .once('acquire', function () { assert.equal(this, pool); ++events; }) - .once('connection', function() { + .once('connection', function () { assert.equal(this, pool); ++events; }) - .once('enqueue', function() { + .once('enqueue', function () { assert.equal(this, pool); ++events; }) - .once('release', function() { + .once('release', function () { assert.equal(this, pool); ++events; @@ -343,27 +343,27 @@ function testEventsPool() { assert.equal( pool.pool.listenerCount(eventName), expectedListeners[eventName], - eventName + eventName, ); } } function testChangeUser() { - const onlyUsername = function(name) { + const onlyUsername = function (name) { return name.substring(0, name.indexOf('@')); }; let connResolved; createConnection(config) - .then(conn => { + .then((conn) => { connResolved = conn; return connResolved.query( - "CREATE USER IF NOT EXISTS 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'" + "CREATE USER IF NOT EXISTS 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'", ); }) .then(() => { connResolved.query( - "CREATE USER IF NOT EXISTS 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'" + "CREATE USER IF NOT EXISTS 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'", ); connResolved.query("GRANT ALL ON *.* TO 'changeuser1'@'%'"); connResolved.query("GRANT ALL ON *.* TO 'changeuser2'@'%'"); @@ -372,37 +372,37 @@ function testChangeUser() { .then(() => { connResolved.changeUser({ user: 'changeuser1', - password: 'changeuser1pass' + password: 'changeuser1pass', }); }) .then(() => connResolved.query('select current_user()')) - .then(result => { + .then((result) => { const rows = result[0]; assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1'); return connResolved.changeUser({ user: 'changeuser2', - password: 'changeuser2pass' + password: 'changeuser2pass', }); }) .then(() => connResolved.query('select current_user()')) - .then(result => { + .then((result) => { const rows = result[0]; assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser2'); return connResolved.changeUser({ user: 'changeuser1', // TODO: re-enable testing passwordSha1 auth. Only works for mysql_native_password, so need to change test to create user with this auth method - password: 'changeuser1pass' + password: 'changeuser1pass', //passwordSha1: Buffer.from('f961d39c82138dcec42b8d0dcb3e40a14fb7e8cd', 'hex') // sha1(changeuser1pass) }); }) .then(() => connResolved.query('select current_user()')) - .then(result => { + .then((result) => { const rows = result[0]; assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1'); doneChangeUser = true; return connResolved.end(); }) - .catch(err => { + .catch((err) => { console.log(err); if (connResolved) { connResolved.end(); @@ -414,14 +414,14 @@ function testChangeUser() { function testConnectionProperties() { let connResolved; createConnection(config) - .then(conn => { + .then((conn) => { connResolved = conn; assert.equal(typeof conn.config, 'object'); assert.ok('queryFormat' in conn.config); assert.equal(typeof conn.threadId, 'number'); return connResolved.end(); }) - .catch(err => { + .catch((err) => { if (connResolved) { connResolved.end(); } @@ -440,7 +440,7 @@ function timebomb(fuse) { }, defuse() { clearTimeout(timebomb); - } + }, }; } @@ -453,7 +453,7 @@ function testPoolConnectionDestroy() { pool .getConnection() - .then(connection => connection.destroy()) + .then((connection) => connection.destroy()) .then(bomb.arm) .then(() => pool.getConnection()) .then(bomb.defuse) @@ -484,6 +484,6 @@ process.on('exit', () => { assert.equal(doneChangeUser, true, 'user not changed'); }); -process.on('unhandledRejection', err => { +process.on('unhandledRejection', (err) => { console.log('error:', err.stack); }); diff --git a/test/integration/regressions/test-#433.js b/test/integration/regressions/test-#433.test.cjs similarity index 85% rename from test/integration/regressions/test-#433.js rename to test/integration/regressions/test-#433.test.cjs index 2abd97f7a9..f79d7ce66d 100644 --- a/test/integration/regressions/test-#433.js +++ b/test/integration/regressions/test-#433.test.cjs @@ -6,13 +6,16 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ charset: 'KOI8R_GENERAL_CI' }); -const assert = require('assert'); +const { assert } = require('poku'); const tableName = 'МояТаблица'; const testFields = ['поле1', 'поле2', 'поле3', 'поле4']; -const testRows = [['привет', 'мир', 47, 7], ['ура', 'тест', 11, 108]]; +const testRows = [ + ['привет', 'мир', 47, 7], + ['ура', 'тест', 11, 108], +]; let actualRows = null; let actualError = null; @@ -20,7 +23,7 @@ let actualError = null; function executeErrorMessageTest() { // tableName does not have closing "`", we do this to have tableName in error string // it is sent back in original encoding (koi8r), we are testing that it's decoded correctly - connection.query(`SELECT * FROM \`${tableName}`, err => { + connection.query(`SELECT * FROM \`${tableName}`, (err) => { actualError = err.message; connection.end(); }); @@ -43,19 +46,19 @@ connection.query( ` \`${testFields[2]}\` int(11) NOT NULL,`, ` \`${testFields[3]}\` int(11) NOT NULL,`, ` PRIMARY KEY (\`${testFields[0]}\`)`, - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', ].join(' '), - err => { + (err) => { assert.ifError(err); connection.query( [ `INSERT INTO \`${tableName}\` VALUES`, `("${testRows[0][0]}","${testRows[0][1]}", ${testRows[0][2]}, ${testRows[0][3]}),`, - `("${testRows[1][0]}","${testRows[1][1]}", ${testRows[1][2]}, ${testRows[1][3]})` + `("${testRows[1][0]}","${testRows[1][1]}", ${testRows[1][2]}, ${testRows[1][3]})`, ].join(' '), - executeTest + executeTest, ); - } + }, ); /* eslint quotes: 0 */ diff --git a/test/integration/regressions/test-#442.js b/test/integration/regressions/test-#442.test.cjs similarity index 81% rename from test/integration/regressions/test-#442.js rename to test/integration/regressions/test-#442.test.cjs index 006bd201e0..1f7936fee3 100644 --- a/test/integration/regressions/test-#442.js +++ b/test/integration/regressions/test-#442.test.cjs @@ -1,12 +1,15 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const tableName = '商城'; const testFields = ['商品类型', '商品说明', '价格', '剩余']; -const testRows = [['商类型', '商品型', 47, 7], ['类商型', '商型品', 11, 108]]; +const testRows = [ + ['商类型', '商品型', 47, 7], + ['类商型', '商型品', 11, 108], +]; let actualRows = null; @@ -27,19 +30,19 @@ connection.query( ` \`${testFields[2]}\` int(11) NOT NULL,`, ` \`${testFields[3]}\` int(11) NOT NULL,`, ` PRIMARY KEY (\`${testFields[0]}\`)`, - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', ].join(' '), - err => { + (err) => { assert.ifError(err); connection.query( [ `INSERT INTO \`${tableName}\` VALUES`, `("${testRows[0][0]}","${testRows[0][1]}", ${testRows[0][2]}, ${testRows[0][3]}),`, - `("${testRows[1][0]}","${testRows[1][1]}", ${testRows[1][2]}, ${testRows[1][3]})` + `("${testRows[1][0]}","${testRows[1][1]}", ${testRows[1][2]}, ${testRows[1][3]})`, ].join(' '), - executeTest + executeTest, ); - } + }, ); process.on('exit', () => { diff --git a/test/integration/regressions/test-#485.js b/test/integration/regressions/test-#485.test.cjs similarity index 82% rename from test/integration/regressions/test-#485.js rename to test/integration/regressions/test-#485.test.cjs index 41e3866901..8582dc8f8a 100644 --- a/test/integration/regressions/test-#485.js +++ b/test/integration/regressions/test-#485.test.cjs @@ -1,8 +1,8 @@ 'use strict'; -const config = require('../../common.js').config; +const config = require('../../common.test.cjs').config; -const assert = require('assert'); +const { assert } = require('poku'); const createPoolPromise = require('../../../promise.js').createPool; const PoolConnection = require('../../../lib/pool_connection.js'); @@ -16,7 +16,7 @@ function createPool(args) { // stub const release = PoolConnection.prototype.release; let releaseCalls = 0; -PoolConnection.prototype.release = function() { +PoolConnection.prototype.release = function () { releaseCalls++; }; @@ -24,11 +24,11 @@ function testPoolPromiseExecuteLeak() { const pool = createPool(); pool .execute('select 1+2 as ttt') - .then(result => { + .then((result) => { assert.equal(result[0][0].ttt, 3); return pool.end(); }) - .catch(err => { + .catch((err) => { assert.ifError(err); }); } diff --git a/test/integration/regressions/test-#617.js b/test/integration/regressions/test-#617.test.cjs similarity index 83% rename from test/integration/regressions/test-#617.js rename to test/integration/regressions/test-#617.test.cjs index 7338c00254..1839117180 100644 --- a/test/integration/regressions/test-#617.js +++ b/test/integration/regressions/test-#617.test.cjs @@ -7,28 +7,27 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } - -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ dateStrings: true }); -const assert = require('assert'); +const { assert } = require('poku'); const tableName = 'dates'; const testFields = ['id', 'date', 'name']; const testRows = [ [1, '2017-07-26 09:36:42.000', 'John'], - [2, '2017-07-26 09:36:42.123', 'Jane'] + [2, '2017-07-26 09:36:42.123', 'Jane'], ]; const expected = [ { id: 1, date: '2017-07-26 09:36:42', - name: 'John' + name: 'John', }, { id: 2, date: '2017-07-26 09:36:42.123', - name: 'Jane' - } + name: 'Jane', + }, ]; let actualRows = null; @@ -48,26 +47,26 @@ connection.query( ` \`${testFields[0]}\` int,`, ` \`${testFields[1]}\` TIMESTAMP(3),`, ` \`${testFields[2]}\` varchar(10)`, - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', ].join(' '), - err => { + (err) => { assert.ifError(err); connection.query( [ `INSERT INTO \`${tableName}\` VALUES`, `(${testRows[0][0]},"${testRows[0][1]}", "${testRows[0][2]}"),`, - `(${testRows[1][0]},"${testRows[1][1]}", "${testRows[1][2]}")` + `(${testRows[1][0]},"${testRows[1][1]}", "${testRows[1][2]}")`, ].join(' '), - executeTest + executeTest, ); - } + }, ); process.on('exit', () => { console.log(actualRows); expected.map((exp, index) => { const row = actualRows[index]; - Object.keys(exp).map(key => { + Object.keys(exp).map((key) => { assert.equal(exp[key], row[key]); }); }); diff --git a/test/integration/regressions/test-#629.js b/test/integration/regressions/test-#629.test.cjs similarity index 82% rename from test/integration/regressions/test-#629.js rename to test/integration/regressions/test-#629.test.cjs index 569448a102..222cfc3290 100644 --- a/test/integration/regressions/test-#629.js +++ b/test/integration/regressions/test-#629.test.cjs @@ -1,31 +1,31 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection({ dateStrings: false, - timezone: 'Z' + timezone: 'Z', }); -const assert = require('assert'); +const { assert } = require('poku'); const tableName = 'dates'; const testFields = ['id', 'date1', 'date2', 'name']; const testRows = [ [1, '2017-07-26 09:36:42.000', '2017-07-29 09:22:24.000', 'John'], - [2, '2017-07-26 09:36:42.123', '2017-07-29 09:22:24.321', 'Jane'] + [2, '2017-07-26 09:36:42.123', '2017-07-29 09:22:24.321', 'Jane'], ]; const expected = [ { id: 1, date1: new Date('2017-07-26T09:36:42.000Z'), date2: new Date('2017-07-29T09:22:24.000Z'), - name: 'John' + name: 'John', }, { id: 2, date1: new Date('2017-07-26T09:36:42.123Z'), date2: new Date('2017-07-29T09:22:24.321Z'), - name: 'Jane' - } + name: 'Jane', + }, ]; let actualRows = null; @@ -46,29 +46,25 @@ connection.query( ` \`${testFields[1]}\` TIMESTAMP(3),`, ` \`${testFields[2]}\` DATETIME(3),`, ` \`${testFields[3]}\` varchar(10)`, - ') ENGINE=InnoDB DEFAULT CHARSET=utf8' + ') ENGINE=InnoDB DEFAULT CHARSET=utf8', ].join(' '), - err => { + (err) => { assert.ifError(err); connection.query( [ `INSERT INTO \`${tableName}\` VALUES`, - `(${testRows[0][0]},"${testRows[0][1]}", "${testRows[0][2]}", "${ - testRows[0][3] - }"),`, - `(${testRows[1][0]},"${testRows[1][1]}", "${testRows[1][2]}", "${ - testRows[1][3] - }")` + `(${testRows[0][0]},"${testRows[0][1]}", "${testRows[0][2]}", "${testRows[0][3]}"),`, + `(${testRows[1][0]},"${testRows[1][1]}", "${testRows[1][2]}", "${testRows[1][3]}")`, ].join(' '), - executeTest + executeTest, ); - } + }, ); process.on('exit', () => { expected.map((exp, index) => { const row = actualRows[index]; - Object.keys(exp).map(key => { + Object.keys(exp).map((key) => { if (key.startsWith('date')) { assert.equal(+exp[key], +row[key]); } else { diff --git a/test/integration/regressions/test-#82.js b/test/integration/regressions/test-#82.test.cjs similarity index 84% rename from test/integration/regressions/test-#82.js rename to test/integration/regressions/test-#82.test.cjs index e7b9e29a06..13a10c9068 100644 --- a/test/integration/regressions/test-#82.js +++ b/test/integration/regressions/test-#82.test.cjs @@ -1,44 +1,44 @@ 'use strict'; -const common = require('../../common'); +const common = require('../../common.test.cjs'); const connection = common.createConnection(); -const assert = require('assert'); +const { assert } = require('poku'); const config = { table1: 'test82t1', table2: 'test82t2', view1: 'view82v1', - view2: 'view82v2' + view2: 'view82v2', }; let results = null; -const prepareTestSet = function(cb) { +const prepareTestSet = function (cb) { connection.query(`drop table if exists ${config.table1}`); connection.query(`drop table if exists ${config.table2}`); connection.query(`drop view if exists ${config.view1}`); connection.query(`drop view if exists ${config.view2}`); connection.query( - `create table ${config.table1} (name1 varchar(20), linkId1 integer(11))` + `create table ${config.table1} (name1 varchar(20), linkId1 integer(11))`, ); connection.query( - `create table ${config.table2} (name2 varchar(20), linkId2 integer(11))` + `create table ${config.table2} (name2 varchar(20), linkId2 integer(11))`, ); connection.query( - `insert into ${config.table1} (name1, linkId1) values ("A", 1),("B", 2),("C", 3),("D", 4)` + `insert into ${config.table1} (name1, linkId1) values ("A", 1),("B", 2),("C", 3),("D", 4)`, ); connection.query( - `insert into ${config.table2} (name2, linkId2) values ("AA", 1),("BB", 2),("CC", 3),("DD", 4)` + `insert into ${config.table2} (name2, linkId2) values ("AA", 1),("BB", 2),("CC", 3),("DD", 4)`, ); connection.query( - `create view ${config.view1} as select name1, linkId1, name2 from ${config.table1} INNER JOIN ${config.table2} ON linkId1 = linkId2` + `create view ${config.view1} as select name1, linkId1, name2 from ${config.table1} INNER JOIN ${config.table2} ON linkId1 = linkId2`, ); connection.query( `create view ${config.view2} as select name1, name2 from ${config.view1}`, - cb + cb, ); }; -prepareTestSet(err => { +prepareTestSet((err) => { assert.ifError(err); connection.query( `select * from ${config.view2} order by name2 desc`, @@ -46,7 +46,7 @@ prepareTestSet(err => { assert.ifError(err); results = rows; connection.end(); - } + }, ); }); @@ -59,4 +59,4 @@ process.on('exit', () => { assert.equal(results[1].name2, 'CC'); assert.equal(results[2].name2, 'BB'); assert.equal(results[3].name2, 'AA'); -}); \ No newline at end of file +}); diff --git a/test/integration/test-auth-switch-multi-factor.js b/test/integration/test-auth-switch-multi-factor.test.cjs similarity index 72% rename from test/integration/test-auth-switch-multi-factor.js rename to test/integration/test-auth-switch-multi-factor.test.cjs index 0774268ef4..e09bd34a57 100644 --- a/test/integration/test-auth-switch-multi-factor.js +++ b/test/integration/test-auth-switch-multi-factor.test.cjs @@ -6,7 +6,7 @@ const mysql = require('../../index.js'); const Command = require('../../lib/commands/command.js'); const Packets = require('../../lib/packets/index.js'); -const assert = require('assert'); +const { assert } = require('poku'); class TestAuthMultiFactor extends Command { constructor(args) { @@ -21,7 +21,7 @@ class TestAuthMultiFactor extends Command { serverVersion: 'node.js rocks', // the server should announce support for the // "MULTI_FACTOR_AUTHENTICATION" capability - capabilityFlags: 0xdfffffff + capabilityFlags: 0xdfffffff, }); this.serverHello = serverHelloPacket; serverHelloPacket.setScrambleData(() => { @@ -38,7 +38,10 @@ class TestAuthMultiFactor extends Command { sendAuthNextFactor(packet, connection) { const asr = Packets.AuthSwitchResponse.fromPacket(packet); - assert.deepStrictEqual(asr.data.toString(), this.args[this.authFactor].pluginName); + assert.deepStrictEqual( + asr.data.toString(), + this.args[this.authFactor].pluginName, + ); if (this.authFactor === 2) { // send OK_Packet after the 3rd authentication factor connection.writeOk(); @@ -56,23 +59,27 @@ class TestAuthMultiFactor extends Command { } } -const server = mysql.createServer(conn => { +const server = mysql.createServer((conn) => { conn.serverConfig = {}; conn.serverConfig.encoding = 'cesu8'; conn.addCommand( - new TestAuthMultiFactor([{ - // already covered by test-auth-switch - pluginName: 'auth_test_plugin1', - pluginData: Buffer.from('foo') - }, { - // 2nd factor auth plugin - pluginName: 'auth_test_plugin2', - pluginData: Buffer.from('bar') - }, { - // 3rd factor auth plugin - pluginName: 'auth_test_plugin3', - pluginData: Buffer.from('baz') - }]) + new TestAuthMultiFactor([ + { + // already covered by test-auth-switch + pluginName: 'auth_test_plugin1', + pluginData: Buffer.from('foo'), + }, + { + // 2nd factor auth plugin + pluginName: 'auth_test_plugin2', + pluginData: Buffer.from('bar'), + }, + { + // 3rd factor auth plugin + pluginName: 'auth_test_plugin3', + pluginData: Buffer.from('baz'), + }, + ]), ); }); @@ -87,17 +94,20 @@ portfinder.getPort((_, port) => { password2: 'secret2', password3: 'secret3', authPlugins: { - auth_test_plugin1 () { + auth_test_plugin1() { return () => { const pluginName = 'auth_test_plugin1'; completed.push(pluginName); return Buffer.from(pluginName); - } + }; }, - auth_test_plugin2 (options) { + auth_test_plugin2(options) { return () => { - if (options.connection.config.password !== options.connection.config.password2) { + if ( + options.connection.config.password !== + options.connection.config.password2 + ) { return assert.fail('Incorrect authentication factor password.'); } @@ -105,11 +115,14 @@ portfinder.getPort((_, port) => { completed.push(pluginName); return Buffer.from(pluginName); - } + }; }, - auth_test_plugin3 (options) { + auth_test_plugin3(options) { return () => { - if (options.connection.config.password !== options.connection.config.password3) { + if ( + options.connection.config.password !== + options.connection.config.password3 + ) { return assert.fail('Incorrect authentication factor password.'); } @@ -117,16 +130,16 @@ portfinder.getPort((_, port) => { completed.push(pluginName); return Buffer.from(pluginName); - } - } - } + }; + }, + }, }); conn.on('connect', () => { assert.deepStrictEqual(completed, [ 'auth_test_plugin1', 'auth_test_plugin2', - 'auth_test_plugin3' + 'auth_test_plugin3', ]); conn.end(); diff --git a/test/integration/test-auth-switch-plugin-async-error.js b/test/integration/test-auth-switch-plugin-async-error.test.cjs similarity index 85% rename from test/integration/test-auth-switch-plugin-async-error.js rename to test/integration/test-auth-switch-plugin-async-error.test.cjs index 53d99ebc99..b601e2dd84 100644 --- a/test/integration/test-auth-switch-plugin-async-error.js +++ b/test/integration/test-auth-switch-plugin-async-error.test.cjs @@ -6,6 +6,7 @@ const mysql = require('../../index.js'); const Command = require('../../lib/commands/command.js'); const Packets = require('../../lib/packets/index.js'); +// Poku intentionally doesn't allow "rewriting" after uncaughtException const assert = require('assert'); class TestAuthSwitchPluginError extends Command { @@ -18,7 +19,7 @@ class TestAuthSwitchPluginError extends Command { const serverHelloPacket = new Packets.Handshake({ // "required" properties protocolVersion: 10, - serverVersion: 'node.js rocks' + serverVersion: 'node.js rocks', }); this.serverHello = serverHelloPacket; serverHelloPacket.setScrambleData(() => { @@ -39,12 +40,12 @@ class TestAuthSwitchPluginError extends Command { } } -const server = mysql.createServer(conn => { +const server = mysql.createServer((conn) => { conn.addCommand( new TestAuthSwitchPluginError({ pluginName: 'auth_test_plugin', - pluginData: Buffer.allocUnsafe(0) - }) + pluginData: Buffer.allocUnsafe(0), + }), ); }); @@ -57,15 +58,15 @@ portfinder.getPort((_, port) => { const conn = mysql.createConnection({ port: port, authPlugins: { - auth_test_plugin () { + auth_test_plugin() { return function () { return Promise.reject(Error('boom')); - } - } - } + }; + }, + }, }); - conn.on('error', err => { + conn.on('error', (err) => { error = err; conn.end(); @@ -73,7 +74,7 @@ portfinder.getPort((_, port) => { }); }); -process.on('uncaughtException', err => { +process.on('uncaughtException', (err) => { // The plugin reports a fatal error assert.equal(error.code, 'AUTH_SWITCH_PLUGIN_ERROR'); assert.equal(error.message, 'boom'); diff --git a/test/integration/test-auth-switch-plugin-error.js b/test/integration/test-auth-switch-plugin-error.test.cjs similarity index 86% rename from test/integration/test-auth-switch-plugin-error.js rename to test/integration/test-auth-switch-plugin-error.test.cjs index 24a0b8d4e3..4722ed3821 100644 --- a/test/integration/test-auth-switch-plugin-error.js +++ b/test/integration/test-auth-switch-plugin-error.test.cjs @@ -6,6 +6,7 @@ const mysql = require('../../index.js'); const Command = require('../../lib/commands/command.js'); const Packets = require('../../lib/packets/index.js'); +// Poku intentionally doesn't allow "rewriting" after uncaughtException const assert = require('assert'); class TestAuthSwitchPluginError extends Command { @@ -18,7 +19,7 @@ class TestAuthSwitchPluginError extends Command { const serverHelloPacket = new Packets.Handshake({ // "required" properties protocolVersion: 10, - serverVersion: 'node.js rocks' + serverVersion: 'node.js rocks', }); this.serverHello = serverHelloPacket; serverHelloPacket.setScrambleData(() => { @@ -39,12 +40,12 @@ class TestAuthSwitchPluginError extends Command { } } -const server = mysql.createServer(conn => { +const server = mysql.createServer((conn) => { conn.addCommand( new TestAuthSwitchPluginError({ pluginName: 'auth_test_plugin', - pluginData: Buffer.allocUnsafe(0) - }) + pluginData: Buffer.allocUnsafe(0), + }), ); }); @@ -59,11 +60,11 @@ portfinder.getPort((_, port) => { authPlugins: { auth_test_plugin: () => { throw new Error('boom'); - } - } + }, + }, }); - conn.on('error', err => { + conn.on('error', (err) => { error = err; conn.end(); @@ -71,7 +72,7 @@ portfinder.getPort((_, port) => { }); }); -process.on('uncaughtException', err => { +process.on('uncaughtException', (err) => { // The plugin reports a fatal error assert.equal(error.code, 'AUTH_SWITCH_PLUGIN_ERROR'); assert.equal(error.message, 'boom'); diff --git a/test/integration/test-auth-switch.js b/test/integration/test-auth-switch.test.cjs similarity index 81% rename from test/integration/test-auth-switch.js rename to test/integration/test-auth-switch.test.cjs index e550e95888..cb02fbfbd1 100644 --- a/test/integration/test-auth-switch.js +++ b/test/integration/test-auth-switch.test.cjs @@ -3,15 +3,15 @@ const mysql = require('../../index.js'); const Command = require('../../lib/commands/command.js'); const Packets = require('../../lib/packets/index.js'); -const {version} = require('../../package.json') +const { version } = require('../../package.json'); -const assert = require('assert'); +const { assert } = require('poku'); -const connectAttributes = {foo: 'bar', baz: 'foo'}; +const connectAttributes = { foo: 'bar', baz: 'foo' }; const defaultConnectAttributes = { _client_name: 'Node-MySQL-2', - _client_version: version + _client_version: version, }; let count = 0; @@ -29,7 +29,7 @@ class TestAuthSwitchHandshake extends Command { connectionId: 1234, statusFlags: 2, characterSet: 8, - capabilityFlags: 0xffffff + capabilityFlags: 0xffffff, }); this.serverHello = serverHelloPacket; serverHelloPacket.setScrambleData(() => { @@ -43,8 +43,10 @@ class TestAuthSwitchHandshake extends Command { assert.equal(clientHelloReply.user, 'test_user'); assert.equal(clientHelloReply.database, 'test_database'); assert.equal(clientHelloReply.authPluginName, 'mysql_native_password'); - assert.deepEqual(clientHelloReply.connectAttributes, - {...connectAttributes, ...defaultConnectAttributes}); + assert.deepEqual(clientHelloReply.connectAttributes, { + ...connectAttributes, + ...defaultConnectAttributes, + }); const asr = new Packets.AuthSwitchRequest(this.args); connection.writePacket(asr.toPacket()); return TestAuthSwitchHandshake.prototype.readClientAuthSwitchResponse; @@ -55,7 +57,7 @@ class TestAuthSwitchHandshake extends Command { count++; if (count < 10) { const asrmd = new Packets.AuthSwitchRequestMoreData( - Buffer.from(`hahaha ${count}`) + Buffer.from(`hahaha ${count}`), ); connection.writePacket(asrmd.toPacket()); return TestAuthSwitchHandshake.prototype.readClientAuthSwitchResponse; @@ -72,14 +74,14 @@ class TestAuthSwitchHandshake extends Command { } } -const server = mysql.createServer(conn => { +const server = mysql.createServer((conn) => { conn.serverConfig = {}; conn.serverConfig.encoding = 'cesu8'; conn.addCommand( new TestAuthSwitchHandshake({ pluginName: 'auth_test_plugin', - pluginData: Buffer.from('f{tU-{K@BhfHt/-4^Z,') - }) + pluginData: Buffer.from('f{tU-{K@BhfHt/-4^Z,'), + }), ); }); @@ -87,9 +89,9 @@ const server = mysql.createServer(conn => { const portfinder = require('portfinder'); portfinder.getPort((err, port) => { - const makeSwitchHandler = function() { + const makeSwitchHandler = function () { let count = 0; - return function(data, cb) { + return function (data, cb) { if (count === 0) { assert.equal(data.pluginName, 'auth_test_plugin'); } else { @@ -108,10 +110,10 @@ portfinder.getPort((err, port) => { database: 'test_database', port: port, authSwitchHandler: makeSwitchHandler(), - connectAttributes: connectAttributes + connectAttributes: connectAttributes, }); - conn.on('connect', data => { + conn.on('connect', (data) => { assert.equal(data.serverVersion, 'node.js rocks'); assert.equal(data.connectionId, 1234); diff --git a/test/integration/test-handshake-unknown-packet-error.js b/test/integration/test-handshake-unknown-packet-error.test.cjs similarity index 89% rename from test/integration/test-handshake-unknown-packet-error.js rename to test/integration/test-handshake-unknown-packet-error.test.cjs index 3b275ba54a..08b2242f8d 100644 --- a/test/integration/test-handshake-unknown-packet-error.js +++ b/test/integration/test-handshake-unknown-packet-error.test.cjs @@ -7,6 +7,7 @@ const Command = require('../../lib/commands/command.js'); const Packet = require('../../lib/packets/packet.js'); const Packets = require('../../lib/packets/index.js'); +// Poku intentionally doesn't allow "rewriting" after uncaughtException const assert = require('assert'); class TestUnknownHandshakePacket extends Command { @@ -19,7 +20,7 @@ class TestUnknownHandshakePacket extends Command { const serverHelloPacket = new Packets.Handshake({ // "required" properties protocolVersion: 10, - serverVersion: 'node.js rocks' + serverVersion: 'node.js rocks', }); this.serverHello = serverHelloPacket; serverHelloPacket.setScrambleData(() => { @@ -45,7 +46,7 @@ class TestUnknownHandshakePacket extends Command { } } -const server = mysql.createServer(conn => { +const server = mysql.createServer((conn) => { conn.addCommand(new TestUnknownHandshakePacket(Buffer.alloc(0))); }); @@ -56,10 +57,10 @@ const portfinder = require('portfinder'); portfinder.getPort((_, port) => { server.listen(port); const conn = mysql.createConnection({ - port: port + port: port, }); - conn.on('error', err => { + conn.on('error', (err) => { error = err; conn.end(); @@ -67,7 +68,7 @@ portfinder.getPort((_, port) => { }); }); -process.on('uncaughtException', err => { +process.on('uncaughtException', (err) => { // The plugin reports a fatal error assert.equal(error.code, 'HANDSHAKE_UNKNOWN_ERROR'); assert.equal(error.message, 'Unexpected packet during handshake phase'); diff --git a/test/integration/test-namedPlaceholders.js b/test/integration/test-namedPlaceholders.js deleted file mode 100644 index 71c7f04585..0000000000 --- a/test/integration/test-namedPlaceholders.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -const createConnection = require('../common.js').createConnection; -const createPool = require('../common.js').createPool; -const test = require('utest'); -const assert = require('assert'); - -const query = - 'SELECT result FROM (SELECT 1 as result) temp WHERE temp.result=:named'; -const values = { named: 1 }; - -test('Test namedPlaceholder as command parameter', { - 'Enabled in connection config, disabled in query command': () => { - // enabled in initial config, disable in test - const c = createConnection({ namedPlaceholders: true }); - c.query({ sql: query, namedPlaceholders: false }, values, err => { - if (!err || !err.sqlMessage.match(/right syntax to use near ':named'/)) { - assert.fail( - `Expected err.sqlMessage to contain "right syntax to use near ':named'" sqlMessage: ${err.sqlMessage}` - ); - } - c.end(); - }); - }, - 'Disabled in connection config, enable query command': () => { - const c = createConnection({ namedPlaceholders: false }); - c.query({ sql: query, namedPlaceholders: true }, values, (err, rows) => { - assert.ifError(err); - assert.equal(rows[0].result, 1); - c.end(); - }); - }, - 'Disabled in connection config, enable execute command': () => { - const c = createConnection({ namedPlaceholders: false }); - c.execute({ sql: query, namedPlaceholders: true }, values, (err, rows) => { - assert.ifError(err); - assert.equal(rows[0].result, 1); - c.end(); - }); - }, - 'Disabled in pool config, enable query command': () => { - const c = createPool({ namedPlaceholders: false }); - c.query({ sql: query, namedPlaceholders: false }, values, (err, rows) => { - assert.ifError(err); - assert.equal(rows[0].result, 1); - c.end(); - }); - } -}); diff --git a/test/integration/test-pool-connect-error.js b/test/integration/test-pool-connect-error.test.cjs similarity index 78% rename from test/integration/test-pool-connect-error.js rename to test/integration/test-pool-connect-error.test.cjs index 72e5cb2e08..51435d4b4d 100644 --- a/test/integration/test-pool-connect-error.js +++ b/test/integration/test-pool-connect-error.test.cjs @@ -2,9 +2,9 @@ const mysql = require('../../index.js'); -const assert = require('assert'); +const { assert } = require('poku'); -const server = mysql.createServer(conn => { +const server = mysql.createServer((conn) => { conn.serverHandshake({ protocolVersion: 10, serverVersion: '5.6.10', @@ -12,9 +12,9 @@ const server = mysql.createServer(conn => { statusFlags: 2, characterSet: 8, capabilityFlags: 0xffffff, - authCallback: function(params, cb) { + authCallback: function (params, cb) { cb(null, { message: 'too many connections', code: 1040 }); - } + }, }); }); @@ -27,9 +27,9 @@ portfinder.getPort((err, port) => { user: 'test_user', password: 'test', database: 'test_database', - port: port + port: port, }); - conn.on('error', err => { + conn.on('error', (err) => { err1 = err; }); @@ -37,10 +37,10 @@ portfinder.getPort((err, port) => { user: 'test_user', password: 'test', database: 'test_database', - port: port + port: port, }); - pool.query('test sql', err => { + pool.query('test sql', (err) => { err2 = err; pool.end(); server.close(); diff --git a/test/integration/test-pool-disconnect.js b/test/integration/test-pool-disconnect.test.cjs similarity index 90% rename from test/integration/test-pool-disconnect.js rename to test/integration/test-pool-disconnect.test.cjs index bab226e4c5..510352163b 100644 --- a/test/integration/test-pool-disconnect.js +++ b/test/integration/test-pool-disconnect.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const assert = require('assert'); -const mysql = require('../common'); +const { assert } = require('poku'); +const mysql = require('../common.test.cjs'); // planetscale does not support KILL, skipping this test // https://planetscale.com/docs/reference/mysql-compatibility @@ -25,7 +25,7 @@ function kill() { if (typeof id !== 'undefined') { // sleep required to give mysql time to close connection, // and callback called after connection with id is really closed - conn.query('kill ?; select sleep(0.05)', [id], err => { + conn.query('kill ?; select sleep(0.05)', [id], (err) => { assert.ifError(err); killCount++; // TODO: this assertion needs to be fixed, after kill @@ -40,7 +40,7 @@ function kill() { }, 5); } -pool.on('connection', conn => { +pool.on('connection', (conn) => { tids.push(conn.threadId); conn.on('error', () => { setTimeout(kill, 5); diff --git a/test/integration/test-pool-end.js b/test/integration/test-pool-end.test.cjs similarity index 84% rename from test/integration/test-pool-end.js rename to test/integration/test-pool-end.test.cjs index 73405e31da..78d51cb5d6 100644 --- a/test/integration/test-pool-end.js +++ b/test/integration/test-pool-end.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const { createPool } = require('../common.js'); -const assert = require('assert'); +const { createPool } = require('../common.test.cjs'); +const { assert } = require('poku'); const pool = createPool(); diff --git a/test/integration/test-pool-release-idle-connection.js b/test/integration/test-pool-release-idle-connection.test.cjs similarity index 93% rename from test/integration/test-pool-release-idle-connection.js rename to test/integration/test-pool-release-idle-connection.test.cjs index 24644e6bb0..7155c28f1a 100644 --- a/test/integration/test-pool-release-idle-connection.js +++ b/test/integration/test-pool-release-idle-connection.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const createPool = require('../common.js').createPool; -const assert = require('assert'); +const createPool = require('../common.test.cjs').createPool; +const { assert } = require('poku'); const pool = new createPool({ connectionLimit: 5, // 5 connections diff --git a/test/integration/test-pool-release.js b/test/integration/test-pool-release.test.cjs similarity index 69% rename from test/integration/test-pool-release.js rename to test/integration/test-pool-release.test.cjs index 292cf79d6f..f65154744e 100644 --- a/test/integration/test-pool-release.js +++ b/test/integration/test-pool-release.test.cjs @@ -1,23 +1,23 @@ 'use strict'; -const createPool = require('../common.js').createPool; -const assert = require('assert'); +const createPool = require('../common.test.cjs').createPool; +const { assert } = require('poku'); const pool = createPool({ - idleTimeout: 15000 + idleTimeout: 15000, }); pool.query('test sql', () => { pool.query('test sql', [], () => { pool.query('test sql', [], () => { pool.query('test sql', [], () => { - pool.query('test sql', () => { - pool.query('test sql').on('error', () => { + pool.query('test sql', () => { + pool.query('test sql').on('error', () => { pool.query('test sql', () => { - pool.execute('test sql', () => { - pool.execute('test sql', () => { - pool.execute('test sql', [], () => { - pool.execute('test sql', () => { + pool.execute('test sql', () => { + pool.execute('test sql', () => { + pool.execute('test sql', [], () => { + pool.execute('test sql', () => { pool.execute('test sql', () => { // TODO change order events are fires so that connection is released before callback // that way this number will be more deterministic diff --git a/test/integration/test-rows-as-array.js b/test/integration/test-rows-as-array.test.cjs similarity index 91% rename from test/integration/test-rows-as-array.js rename to test/integration/test-rows-as-array.test.cjs index 042f60d20f..a8ba204d3b 100644 --- a/test/integration/test-rows-as-array.js +++ b/test/integration/test-rows-as-array.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const createConnection = require('../common.js').createConnection; -const assert = require('assert'); +const createConnection = require('../common.test.cjs').createConnection; +const { assert } = require('poku'); // enabled in initial config, disable in some tets const c = createConnection({ rowsAsArray: true }); diff --git a/test/integration/test-server-close.js b/test/integration/test-server-close.test.cjs similarity index 66% rename from test/integration/test-server-close.js rename to test/integration/test-server-close.test.cjs index 23df672de2..f5fb76cd22 100644 --- a/test/integration/test-server-close.js +++ b/test/integration/test-server-close.test.cjs @@ -3,8 +3,10 @@ 'use strict'; const errors = require('../../lib/constants/errors'); -const common = require('../common'); +const common = require('../common.test.cjs'); const connection = common.createConnection(); + +// Poku intentionally doesn't allow "rewriting" after uncaughtException const assert = require('assert'); if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { @@ -12,12 +14,11 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } - const customWaitTimeout = 1; // seconds let error; -connection.on('error', err => { +connection.on('error', (err) => { error = err; connection.close(); @@ -27,18 +28,24 @@ connection.query(`set wait_timeout=${customWaitTimeout}`, () => { setTimeout(() => {}, customWaitTimeout * 1000 * 2); }); -process.on('uncaughtException', err => { +process.on('uncaughtException', (err) => { // The ERR Packet is only sent by MySQL server 8.0.24 or higher, so we // need to account for the fact it is not sent by older server versions. if (err.code !== 'ERR_ASSERTION') { throw err; } - assert.equal(error.message, 'Connection lost: The server closed the connection.'); + assert.equal( + error.message, + 'Connection lost: The server closed the connection.', + ); assert.equal(error.code, 'PROTOCOL_CONNECTION_LOST'); }); process.on('exit', () => { - assert.equal(error.message, 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.'); + assert.equal( + error.message, + 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.', + ); assert.equal(error.code, errors.ER_CLIENT_INTERACTION_TIMEOUT); }); diff --git a/test/run.js b/test/run.js deleted file mode 100755 index 2282f01238..0000000000 --- a/test/run.js +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env node - -'use strict'; - -const fs = require('node:fs'); -const path = require('node:path'); -const { spawn } = require('node:child_process'); -const { EOL } = require('node:os'); - -const escapeRegExp = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - -const startTime = Date.now(); -const filter = process.env.FILTER ? new RegExp(escapeRegExp(process.env.FILTER), 'i') : null; - -const format = { - time: startTime => { - const elapsedTime = Date.now() - startTime; - const hours = Math.floor((elapsedTime / (1000 * 60 * 60)) % 24) - .toString() - .padStart(2, '0'); - const minutes = Math.floor((elapsedTime / (1000 * 60)) % 60) - .toString() - .padStart(2, '0'); - const seconds = Math.floor((elapsedTime / 1000) % 60) - .toString() - .padStart(2, '0'); - return `${hours}:${minutes}:${seconds}`; - }, - counter: (current, total, pad = ' ') => { - const totalDigits = String(total).length; - return `${String(current).padStart(totalDigits, pad)}`; - }, - percent: (current, total) => { - const percentage = ((current / total) * 100).toFixed(0); - return `${format.counter(percentage, 100)}%`; - }, -}; - -const getFiles = (dirPath, files = []) => { - const currentFiles = fs.readdirSync(dirPath); - - for (const file of currentFiles) { - const fullPath = path.join(dirPath, file); - - if (fs.statSync(fullPath).isDirectory()) { - getFiles(fullPath, files); - } else if ( - (fullPath.endsWith('.js') || fullPath.endsWith('.mjs')) && - (!filter || fullPath.match(filter)) - ) { - files.push(fullPath); - } - } - - return files; -}; - -const runTestFile = filePath => - new Promise(resolve => { - const child = spawn('node', [filePath], { stdio: 'inherit' }); - - child.on('close', code => { - if (code === 0) { - resolve(true); - } else { - resolve(false); - } - }); - - child.on('error', err => { - console.log(`Failed to start test: ${filePath}`, err); - resolve(false); - }); - }); - -const runTests = async dir => { - const testDir = path.join(__dirname, dir); - const files = getFiles(testDir); - const totalTests = files.length; - - let passed = true; - - console.log(`${EOL}Directory: ${path.relative(process.cwd(), testDir)}${EOL}`); - - for (let i = 0; i < files.length; i++) { - const filePath = files[i]; - const fileRelative = path.relative(process.cwd(), filePath); - const testPassed = await runTestFile(filePath); - const testNumber = i + 1; - const elapsedTime = format.time(startTime); - const counter = format.counter( - testNumber, - totalTests, - ); - const percent = format.percent( - testNumber, - totalTests, - ); - const command = `node ${fileRelative}`; - const log = `${elapsedTime} ${counter}/${totalTests} ${percent} ${command}`; - - if (testPassed) { - console.log(`✅ [ 0 ${log} ]`, EOL); - } else { - console.log(`❌ [ 1 ${log} ]`, EOL); - passed = false; - } - } - - return passed; -}; - -(async () => { - const unitTestsPassed = await runTests('./unit'); - const integrationTestsPassed = await runTests('./integration'); - - if (!unitTestsPassed || !integrationTestsPassed) { - console.log('Some tests failed.'); - process.exit(1); - } else { - console.log('All tests passed.'); - process.exit(0); - } -})(); - -process.on('exit', code => { - console.log(`About to exit with code: ${code}`); -}); - -process.on('unhandledRejection', reason => { - console.log('unhandledRejection', reason); - process.exit(1); -}); - -process.on('uncaughtException', err => { - console.log('uncaughtException', err); - process.exit(1); -}); diff --git a/test/tsc-build/helpers.ts b/test/tsc-build/helpers.test.ts similarity index 89% rename from test/tsc-build/helpers.ts rename to test/tsc-build/helpers.test.ts index e8112e7abe..0171818e1d 100644 --- a/test/tsc-build/helpers.ts +++ b/test/tsc-build/helpers.test.ts @@ -1,7 +1,7 @@ -import { mysql, mysqlp } from './index.js'; +import { mysql, mysqlp } from './index.test.js'; export const isResultSetHeader = ( - data: unknown + data: unknown, ): data is mysql.ResultSetHeader | mysqlp.ResultSetHeader => { if (!data || typeof data !== 'object') return false; @@ -18,7 +18,7 @@ export const isResultSetHeader = ( }; export const isOkPacket = ( - data: unknown + data: unknown, ): data is mysql.OkPacket | mysqlp.OkPacket => { if (!data || typeof data !== 'object') return false; diff --git a/test/tsc-build/index.ts b/test/tsc-build/index.test.ts similarity index 100% rename from test/tsc-build/index.ts rename to test/tsc-build/index.test.ts diff --git a/test/tsc-build/mysql/baseConnection.ts b/test/tsc-build/mysql/baseConnection.test.ts similarity index 92% rename from test/tsc-build/mysql/baseConnection.ts rename to test/tsc-build/mysql/baseConnection.test.ts index 09f0fcba08..0c179b177b 100644 --- a/test/tsc-build/mysql/baseConnection.ts +++ b/test/tsc-build/mysql/baseConnection.test.ts @@ -1,4 +1,4 @@ -import { mysql } from '../index.js'; +import { mysql } from '../index.test.js'; export const access: mysql.ConnectionOptions = { host: '', diff --git a/test/tsc-build/mysql/constants/CharsetToEncoding.ts b/test/tsc-build/mysql/constants/CharsetToEncoding.test.ts similarity index 76% rename from test/tsc-build/mysql/constants/CharsetToEncoding.ts rename to test/tsc-build/mysql/constants/CharsetToEncoding.test.ts index 4b6a55f348..cbd4e5384d 100644 --- a/test/tsc-build/mysql/constants/CharsetToEncoding.ts +++ b/test/tsc-build/mysql/constants/CharsetToEncoding.test.ts @@ -1,4 +1,4 @@ -import { mysql } from '../../index.js'; +import { mysql } from '../../index.test.js'; const charsetToEncoding: string[] = mysql.CharsetToEncoding; const utf8: string = charsetToEncoding[0]; diff --git a/test/tsc-build/mysql/constants/Charsets.ts b/test/tsc-build/mysql/constants/Charsets.test.ts similarity index 76% rename from test/tsc-build/mysql/constants/Charsets.ts rename to test/tsc-build/mysql/constants/Charsets.test.ts index 65dbe424b9..eec3ed0d56 100644 --- a/test/tsc-build/mysql/constants/Charsets.ts +++ b/test/tsc-build/mysql/constants/Charsets.test.ts @@ -1,4 +1,4 @@ -import { mysql } from '../../index.js'; +import { mysql } from '../../index.test.js'; const BIG5_CHINESE_CI: number = mysql.Charsets.BIG5_CHINESE_CI; const BIG5: number = mysql.Charsets.BIG5; diff --git a/test/tsc-build/mysql/constants/Types.ts b/test/tsc-build/mysql/constants/Types.test.ts similarity index 77% rename from test/tsc-build/mysql/constants/Types.ts rename to test/tsc-build/mysql/constants/Types.test.ts index 30f231a796..4f72875152 100644 --- a/test/tsc-build/mysql/constants/Types.ts +++ b/test/tsc-build/mysql/constants/Types.test.ts @@ -1,4 +1,4 @@ -import { mysql } from '../../index.js'; +import { mysql } from '../../index.test.js'; const BLOB: number = mysql.Types.BLOB; const DECIMAL: string = mysql.Types[0x00]; diff --git a/test/tsc-build/mysql/createConnection/callbacks/execute.ts b/test/tsc-build/mysql/createConnection/callbacks/execute.test.ts similarity index 93% rename from test/tsc-build/mysql/createConnection/callbacks/execute.ts rename to test/tsc-build/mysql/createConnection/callbacks/execute.test.ts index 63a8979e5a..2796c481ff 100644 --- a/test/tsc-build/mysql/createConnection/callbacks/execute.ts +++ b/test/tsc-build/mysql/createConnection/callbacks/execute.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; { const db = mysql.createConnection(access); diff --git a/test/tsc-build/mysql/createConnection/callbacks/query.ts b/test/tsc-build/mysql/createConnection/callbacks/query.test.ts similarity index 93% rename from test/tsc-build/mysql/createConnection/callbacks/query.ts rename to test/tsc-build/mysql/createConnection/callbacks/query.test.ts index 45b0327ec4..e833f13c81 100644 --- a/test/tsc-build/mysql/createConnection/callbacks/query.ts +++ b/test/tsc-build/mysql/createConnection/callbacks/query.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; { const db = mysql.createConnection(access); diff --git a/test/tsc-build/mysql/createConnection/promise/execute.ts b/test/tsc-build/mysql/createConnection/promise/execute.test.ts similarity index 93% rename from test/tsc-build/mysql/createConnection/promise/execute.ts rename to test/tsc-build/mysql/createConnection/promise/execute.test.ts index 88c422b0bf..3d7efe14bf 100644 --- a/test/tsc-build/mysql/createConnection/promise/execute.ts +++ b/test/tsc-build/mysql/createConnection/promise/execute.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; (async () => { const db = mysql.createConnection(access).promise(); diff --git a/test/tsc-build/mysql/createConnection/promise/query.ts b/test/tsc-build/mysql/createConnection/promise/query.test.ts similarity index 93% rename from test/tsc-build/mysql/createConnection/promise/query.ts rename to test/tsc-build/mysql/createConnection/promise/query.test.ts index c899463462..146c99e5dc 100644 --- a/test/tsc-build/mysql/createConnection/promise/query.ts +++ b/test/tsc-build/mysql/createConnection/promise/query.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; (async () => { const db = mysql.createConnection(access).promise(); diff --git a/test/tsc-build/mysql/createPool/callbacks/connection.ts b/test/tsc-build/mysql/createPool/callbacks/connection.test.ts similarity index 71% rename from test/tsc-build/mysql/createPool/callbacks/connection.ts rename to test/tsc-build/mysql/createPool/callbacks/connection.test.ts index 07274809f5..7b16fe76fd 100644 --- a/test/tsc-build/mysql/createPool/callbacks/connection.ts +++ b/test/tsc-build/mysql/createPool/callbacks/connection.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/callbacks/createPool.ts b/test/tsc-build/mysql/createPool/callbacks/createPool.test.ts similarity index 66% rename from test/tsc-build/mysql/createPool/callbacks/createPool.ts rename to test/tsc-build/mysql/createPool/callbacks/createPool.test.ts index c671358bb7..508b08ebc4 100644 --- a/test/tsc-build/mysql/createPool/callbacks/createPool.ts +++ b/test/tsc-build/mysql/createPool/callbacks/createPool.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { uriAccess, access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { uriAccess, access } from '../../baseConnection.test.js'; (() => { let uriPool: mysql.Pool | null = null; diff --git a/test/tsc-build/mysql/createPool/callbacks/execute.ts b/test/tsc-build/mysql/createPool/callbacks/execute.test.ts similarity index 96% rename from test/tsc-build/mysql/createPool/callbacks/execute.ts rename to test/tsc-build/mysql/createPool/callbacks/execute.test.ts index 3a1deaef65..a13b7ca0c0 100644 --- a/test/tsc-build/mysql/createPool/callbacks/execute.ts +++ b/test/tsc-build/mysql/createPool/callbacks/execute.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; { const db = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/callbacks/getConnection.ts b/test/tsc-build/mysql/createPool/callbacks/getConnection.test.ts similarity index 71% rename from test/tsc-build/mysql/createPool/callbacks/getConnection.ts rename to test/tsc-build/mysql/createPool/callbacks/getConnection.test.ts index 3a60d6f250..5cc4552365 100644 --- a/test/tsc-build/mysql/createPool/callbacks/getConnection.ts +++ b/test/tsc-build/mysql/createPool/callbacks/getConnection.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/callbacks/query.ts b/test/tsc-build/mysql/createPool/callbacks/query.test.ts similarity index 96% rename from test/tsc-build/mysql/createPool/callbacks/query.ts rename to test/tsc-build/mysql/createPool/callbacks/query.test.ts index 1661c70ed0..fcfcac83df 100644 --- a/test/tsc-build/mysql/createPool/callbacks/query.ts +++ b/test/tsc-build/mysql/createPool/callbacks/query.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; { const db = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/callbacks/release.ts b/test/tsc-build/mysql/createPool/callbacks/release.test.ts similarity index 74% rename from test/tsc-build/mysql/createPool/callbacks/release.ts rename to test/tsc-build/mysql/createPool/callbacks/release.test.ts index 2e39a6cdfc..eb98d64858 100644 --- a/test/tsc-build/mysql/createPool/callbacks/release.ts +++ b/test/tsc-build/mysql/createPool/callbacks/release.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/callbacks/releaseConnection.ts b/test/tsc-build/mysql/createPool/callbacks/releaseConnection.test.ts similarity index 52% rename from test/tsc-build/mysql/createPool/callbacks/releaseConnection.ts rename to test/tsc-build/mysql/createPool/callbacks/releaseConnection.test.ts index e235e78fbc..a992dac04b 100644 --- a/test/tsc-build/mysql/createPool/callbacks/releaseConnection.ts +++ b/test/tsc-build/mysql/createPool/callbacks/releaseConnection.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/promise/connection.ts b/test/tsc-build/mysql/createPool/promise/connection.test.ts similarity index 74% rename from test/tsc-build/mysql/createPool/promise/connection.ts rename to test/tsc-build/mysql/createPool/promise/connection.test.ts index b8b012afa6..4b2ddad4dc 100644 --- a/test/tsc-build/mysql/createPool/promise/connection.ts +++ b/test/tsc-build/mysql/createPool/promise/connection.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/promise/execute.ts b/test/tsc-build/mysql/createPool/promise/execute.test.ts similarity index 96% rename from test/tsc-build/mysql/createPool/promise/execute.ts rename to test/tsc-build/mysql/createPool/promise/execute.test.ts index 1d7ff7c5cb..95585de308 100644 --- a/test/tsc-build/mysql/createPool/promise/execute.ts +++ b/test/tsc-build/mysql/createPool/promise/execute.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; (async () => { const db = mysql.createPool(access).promise(); diff --git a/test/tsc-build/mysql/createPool/promise/getConnection.ts b/test/tsc-build/mysql/createPool/promise/getConnection.test.ts similarity index 73% rename from test/tsc-build/mysql/createPool/promise/getConnection.ts rename to test/tsc-build/mysql/createPool/promise/getConnection.test.ts index fd7e9cdcf3..86a76b2ca6 100644 --- a/test/tsc-build/mysql/createPool/promise/getConnection.ts +++ b/test/tsc-build/mysql/createPool/promise/getConnection.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/promise/promise.ts b/test/tsc-build/mysql/createPool/promise/promise.test.ts similarity index 74% rename from test/tsc-build/mysql/createPool/promise/promise.ts rename to test/tsc-build/mysql/createPool/promise/promise.test.ts index 0c8efe737b..5144ca6b82 100644 --- a/test/tsc-build/mysql/createPool/promise/promise.ts +++ b/test/tsc-build/mysql/createPool/promise/promise.test.ts @@ -1,5 +1,5 @@ -import { mysql, mysqlp } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql, mysqlp } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; (async () => { let pool: mysql.Pool | null = null; diff --git a/test/tsc-build/mysql/createPool/promise/query.ts b/test/tsc-build/mysql/createPool/promise/query.test.ts similarity index 96% rename from test/tsc-build/mysql/createPool/promise/query.ts rename to test/tsc-build/mysql/createPool/promise/query.test.ts index 45928743d4..6e1eb53854 100644 --- a/test/tsc-build/mysql/createPool/promise/query.ts +++ b/test/tsc-build/mysql/createPool/promise/query.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access, sql, sqlPS, values } from '../../baseConnection.test.js'; (async () => { const db = mysql.createPool(access).promise(); diff --git a/test/tsc-build/mysql/createPool/promise/release.ts b/test/tsc-build/mysql/createPool/promise/release.test.ts similarity index 76% rename from test/tsc-build/mysql/createPool/promise/release.ts rename to test/tsc-build/mysql/createPool/promise/release.test.ts index 7bb3d77e17..496bbfdd6f 100644 --- a/test/tsc-build/mysql/createPool/promise/release.ts +++ b/test/tsc-build/mysql/createPool/promise/release.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPool/promise/releaseConnection.ts b/test/tsc-build/mysql/createPool/promise/releaseConnection.test.ts similarity index 59% rename from test/tsc-build/mysql/createPool/promise/releaseConnection.ts rename to test/tsc-build/mysql/createPool/promise/releaseConnection.test.ts index 0b9a1ef31b..8b20716f6b 100644 --- a/test/tsc-build/mysql/createPool/promise/releaseConnection.ts +++ b/test/tsc-build/mysql/createPool/promise/releaseConnection.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../../index.js'; -import { access } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { access } from '../../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/mysql/createPoolCluster/add.ts b/test/tsc-build/mysql/createPoolCluster/add.test.ts similarity index 77% rename from test/tsc-build/mysql/createPoolCluster/add.ts rename to test/tsc-build/mysql/createPoolCluster/add.test.ts index e5e72690bd..12ca88ee44 100644 --- a/test/tsc-build/mysql/createPoolCluster/add.ts +++ b/test/tsc-build/mysql/createPoolCluster/add.test.ts @@ -1,5 +1,5 @@ -import { mysql } from '../../index.js'; -import { access, uriAccess } from '../baseConnection.js'; +import { mysql } from '../../index.test.js'; +import { access, uriAccess } from '../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/mysql/createPoolCluster/getConnection.ts b/test/tsc-build/mysql/createPoolCluster/getConnection.test.ts similarity index 93% rename from test/tsc-build/mysql/createPoolCluster/getConnection.ts rename to test/tsc-build/mysql/createPoolCluster/getConnection.test.ts index 76c7c5ad33..5ccfaa3583 100644 --- a/test/tsc-build/mysql/createPoolCluster/getConnection.ts +++ b/test/tsc-build/mysql/createPoolCluster/getConnection.test.ts @@ -1,5 +1,11 @@ -import { mysql } from '../../index.js'; -import { access, uriAccess, sql, sqlPS, values } from '../baseConnection.js'; +import { mysql } from '../../index.test.js'; +import { + access, + uriAccess, + sql, + sqlPS, + values, +} from '../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/mysql/createPoolCluster/of/getConnection.ts b/test/tsc-build/mysql/createPoolCluster/of/getConnection.test.ts similarity index 92% rename from test/tsc-build/mysql/createPoolCluster/of/getConnection.ts rename to test/tsc-build/mysql/createPoolCluster/of/getConnection.test.ts index fc3a0fa623..79e1e1f267 100644 --- a/test/tsc-build/mysql/createPoolCluster/of/getConnection.ts +++ b/test/tsc-build/mysql/createPoolCluster/of/getConnection.test.ts @@ -1,5 +1,11 @@ -import { mysql } from '../../../index.js'; -import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { + access, + uriAccess, + sql, + sqlPS, + values, +} from '../../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/mysql/createPoolCluster/of/of.ts b/test/tsc-build/mysql/createPoolCluster/of/of.test.ts similarity index 93% rename from test/tsc-build/mysql/createPoolCluster/of/of.ts rename to test/tsc-build/mysql/createPoolCluster/of/of.test.ts index 6d1206e6bb..bdeb98fde1 100644 --- a/test/tsc-build/mysql/createPoolCluster/of/of.ts +++ b/test/tsc-build/mysql/createPoolCluster/of/of.test.ts @@ -1,5 +1,11 @@ -import { mysql } from '../../../index.js'; -import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysql } from '../../../index.test.js'; +import { + access, + uriAccess, + sql, + sqlPS, + values, +} from '../../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/mysql/parsers/clearParserCache.test.ts b/test/tsc-build/mysql/parsers/clearParserCache.test.ts new file mode 100644 index 0000000000..220341e55e --- /dev/null +++ b/test/tsc-build/mysql/parsers/clearParserCache.test.ts @@ -0,0 +1,3 @@ +import { mysql } from '../../index.test.js'; + +mysql.clearParserCache(); diff --git a/test/tsc-build/mysql/parsers/clearParserCache.ts b/test/tsc-build/mysql/parsers/clearParserCache.ts deleted file mode 100644 index 7b580a3487..0000000000 --- a/test/tsc-build/mysql/parsers/clearParserCache.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { mysql } from '../../index.js'; - -mysql.clearParserCache(); diff --git a/test/tsc-build/mysql/parsers/setMaxParserCache.ts b/test/tsc-build/mysql/parsers/setMaxParserCache.test.ts similarity index 70% rename from test/tsc-build/mysql/parsers/setMaxParserCache.ts rename to test/tsc-build/mysql/parsers/setMaxParserCache.test.ts index 8a8ffc6da6..849e856804 100644 --- a/test/tsc-build/mysql/parsers/setMaxParserCache.ts +++ b/test/tsc-build/mysql/parsers/setMaxParserCache.test.ts @@ -1,4 +1,4 @@ -import { mysql } from '../../index.js'; +import { mysql } from '../../index.test.js'; mysql.setMaxParserCache(1000); diff --git a/test/tsc-build/promise/baseConnection.ts b/test/tsc-build/promise/baseConnection.test.ts similarity index 90% rename from test/tsc-build/promise/baseConnection.ts rename to test/tsc-build/promise/baseConnection.test.ts index e9bcf9899f..89d4ca3b0c 100644 --- a/test/tsc-build/promise/baseConnection.ts +++ b/test/tsc-build/promise/baseConnection.test.ts @@ -1,4 +1,4 @@ -import { mysqlp as mysql } from '../index.js'; +import { mysqlp as mysql } from '../index.test.js'; export const access: mysql.ConnectionOptions = { host: '', diff --git a/test/tsc-build/promise/constants/CharsetToEncoding.ts b/test/tsc-build/promise/constants/CharsetToEncoding.test.ts similarity index 72% rename from test/tsc-build/promise/constants/CharsetToEncoding.ts rename to test/tsc-build/promise/constants/CharsetToEncoding.test.ts index 852a046134..212381fda6 100644 --- a/test/tsc-build/promise/constants/CharsetToEncoding.ts +++ b/test/tsc-build/promise/constants/CharsetToEncoding.test.ts @@ -1,4 +1,4 @@ -import { mysqlp as mysql } from '../../index.js'; +import { mysqlp as mysql } from '../../index.test.js'; const charsetToEncoding: string[] = mysql.CharsetToEncoding; const utf8: string = charsetToEncoding[0]; diff --git a/test/tsc-build/promise/constants/Charsets.ts b/test/tsc-build/promise/constants/Charsets.test.ts similarity index 72% rename from test/tsc-build/promise/constants/Charsets.ts rename to test/tsc-build/promise/constants/Charsets.test.ts index 1e5f1b668b..a38ea7c8a9 100644 --- a/test/tsc-build/promise/constants/Charsets.ts +++ b/test/tsc-build/promise/constants/Charsets.test.ts @@ -1,4 +1,4 @@ -import { mysqlp as mysql } from '../../index.js'; +import { mysqlp as mysql } from '../../index.test.js'; const BIG5_CHINESE_CI: number = mysql.Charsets.BIG5_CHINESE_CI; const BIG5: number = mysql.Charsets.BIG5; diff --git a/test/tsc-build/promise/constants/Types.ts b/test/tsc-build/promise/constants/Types.test.ts similarity index 74% rename from test/tsc-build/promise/constants/Types.ts rename to test/tsc-build/promise/constants/Types.test.ts index 565ed3883e..f8761077c3 100644 --- a/test/tsc-build/promise/constants/Types.ts +++ b/test/tsc-build/promise/constants/Types.test.ts @@ -1,4 +1,4 @@ -import { mysqlp as mysql } from '../../index.js'; +import { mysqlp as mysql } from '../../index.test.js'; const BLOB: number = mysql.Types.BLOB; const DECIMAL: string = mysql.Types[0x00]; diff --git a/test/tsc-build/promise/createConnection/execute.ts b/test/tsc-build/promise/createConnection/execute.test.ts similarity index 86% rename from test/tsc-build/promise/createConnection/execute.ts rename to test/tsc-build/promise/createConnection/execute.test.ts index fdba148b4e..67e11a6f88 100644 --- a/test/tsc-build/promise/createConnection/execute.ts +++ b/test/tsc-build/promise/createConnection/execute.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access, sql, sqlPS, values } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access, sql, sqlPS, values } from '../baseConnection.test.js'; (async () => { const db = await mysql.createConnection(access); diff --git a/test/tsc-build/promise/createConnection/query.ts b/test/tsc-build/promise/createConnection/query.test.ts similarity index 86% rename from test/tsc-build/promise/createConnection/query.ts rename to test/tsc-build/promise/createConnection/query.test.ts index 4ed721a607..4070c78e93 100644 --- a/test/tsc-build/promise/createConnection/query.ts +++ b/test/tsc-build/promise/createConnection/query.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access, sql, sqlPS, values } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access, sql, sqlPS, values } from '../baseConnection.test.js'; (async () => { const db = await mysql.createConnection(access); diff --git a/test/tsc-build/promise/createPool/connection.ts b/test/tsc-build/promise/createPool/connection.test.ts similarity index 72% rename from test/tsc-build/promise/createPool/connection.ts rename to test/tsc-build/promise/createPool/connection.test.ts index 7806887b84..2245041f6e 100644 --- a/test/tsc-build/promise/createPool/connection.ts +++ b/test/tsc-build/promise/createPool/connection.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access } from '../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/promise/createPool/createPool.ts b/test/tsc-build/promise/createPool/createPool.test.ts similarity index 65% rename from test/tsc-build/promise/createPool/createPool.ts rename to test/tsc-build/promise/createPool/createPool.test.ts index 83a930f0e1..5073aaf758 100644 --- a/test/tsc-build/promise/createPool/createPool.ts +++ b/test/tsc-build/promise/createPool/createPool.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { uriAccess, access } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { uriAccess, access } from '../baseConnection.test.js'; (() => { let uriPool: mysql.Pool | null = null; diff --git a/test/tsc-build/promise/createPool/execute.ts b/test/tsc-build/promise/createPool/execute.test.ts similarity index 93% rename from test/tsc-build/promise/createPool/execute.ts rename to test/tsc-build/promise/createPool/execute.test.ts index e32c3967a9..1e1695f4c3 100644 --- a/test/tsc-build/promise/createPool/execute.ts +++ b/test/tsc-build/promise/createPool/execute.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access, sql, sqlPS, values } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access, sql, sqlPS, values } from '../baseConnection.test.js'; (async () => { const db = mysql.createPool(access); diff --git a/test/tsc-build/promise/createPool/getConnection.ts b/test/tsc-build/promise/createPool/getConnection.test.ts similarity index 73% rename from test/tsc-build/promise/createPool/getConnection.ts rename to test/tsc-build/promise/createPool/getConnection.test.ts index 932883ec4e..c8f4d868de 100644 --- a/test/tsc-build/promise/createPool/getConnection.ts +++ b/test/tsc-build/promise/createPool/getConnection.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access } from '../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/promise/createPool/query.ts b/test/tsc-build/promise/createPool/query.test.ts similarity index 92% rename from test/tsc-build/promise/createPool/query.ts rename to test/tsc-build/promise/createPool/query.test.ts index 10448fc671..17ddfc5e4d 100644 --- a/test/tsc-build/promise/createPool/query.ts +++ b/test/tsc-build/promise/createPool/query.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access, sql, sqlPS, values } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access, sql, sqlPS, values } from '../baseConnection.test.js'; (async () => { const db = mysql.createPool(access); diff --git a/test/tsc-build/promise/createPool/release.ts b/test/tsc-build/promise/createPool/release.test.ts similarity index 75% rename from test/tsc-build/promise/createPool/release.ts rename to test/tsc-build/promise/createPool/release.test.ts index 853e02eeb4..fd62bb7e56 100644 --- a/test/tsc-build/promise/createPool/release.ts +++ b/test/tsc-build/promise/createPool/release.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access } from '../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/promise/createPool/releaseConnection.ts b/test/tsc-build/promise/createPool/releaseConnection.test.ts similarity index 56% rename from test/tsc-build/promise/createPool/releaseConnection.ts rename to test/tsc-build/promise/createPool/releaseConnection.test.ts index d86bafb0f8..b4528501c3 100644 --- a/test/tsc-build/promise/createPool/releaseConnection.ts +++ b/test/tsc-build/promise/createPool/releaseConnection.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access } from '../baseConnection.test.js'; (async () => { const pool = mysql.createPool(access); diff --git a/test/tsc-build/promise/createPoolCluster/add.ts b/test/tsc-build/promise/createPoolCluster/add.test.ts similarity index 76% rename from test/tsc-build/promise/createPoolCluster/add.ts rename to test/tsc-build/promise/createPoolCluster/add.test.ts index fd60548749..ba38ac6c47 100644 --- a/test/tsc-build/promise/createPoolCluster/add.ts +++ b/test/tsc-build/promise/createPoolCluster/add.test.ts @@ -1,5 +1,5 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access, uriAccess } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { access, uriAccess } from '../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/promise/createPoolCluster/getConnection.ts b/test/tsc-build/promise/createPoolCluster/getConnection.test.ts similarity index 92% rename from test/tsc-build/promise/createPoolCluster/getConnection.ts rename to test/tsc-build/promise/createPoolCluster/getConnection.test.ts index 21d0397fb1..878fd0901e 100644 --- a/test/tsc-build/promise/createPoolCluster/getConnection.ts +++ b/test/tsc-build/promise/createPoolCluster/getConnection.test.ts @@ -1,5 +1,11 @@ -import { mysqlp as mysql } from '../../index.js'; -import { access, uriAccess, sql, sqlPS, values } from '../baseConnection.js'; +import { mysqlp as mysql } from '../../index.test.js'; +import { + access, + uriAccess, + sql, + sqlPS, + values, +} from '../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/promise/createPoolCluster/of/getConnection.ts b/test/tsc-build/promise/createPoolCluster/of/getConnection.test.ts similarity index 92% rename from test/tsc-build/promise/createPoolCluster/of/getConnection.ts rename to test/tsc-build/promise/createPoolCluster/of/getConnection.test.ts index 5730a9f766..c2341c99a8 100644 --- a/test/tsc-build/promise/createPoolCluster/of/getConnection.ts +++ b/test/tsc-build/promise/createPoolCluster/of/getConnection.test.ts @@ -1,5 +1,11 @@ -import { mysqlp as mysql } from '../../../index.js'; -import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysqlp as mysql } from '../../../index.test.js'; +import { + access, + uriAccess, + sql, + sqlPS, + values, +} from '../../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/promise/createPoolCluster/of/of.ts b/test/tsc-build/promise/createPoolCluster/of/of.test.ts similarity index 92% rename from test/tsc-build/promise/createPoolCluster/of/of.ts rename to test/tsc-build/promise/createPoolCluster/of/of.test.ts index 78325ec9fe..2ab60f8144 100644 --- a/test/tsc-build/promise/createPoolCluster/of/of.ts +++ b/test/tsc-build/promise/createPoolCluster/of/of.test.ts @@ -1,5 +1,11 @@ -import { mysqlp as mysql } from '../../../index.js'; -import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; +import { mysqlp as mysql } from '../../../index.test.js'; +import { + access, + uriAccess, + sql, + sqlPS, + values, +} from '../../baseConnection.test.js'; const poolCluster = mysql.createPoolCluster(); diff --git a/test/tsc-build/promise/parsers/clearParserCache.test.ts b/test/tsc-build/promise/parsers/clearParserCache.test.ts new file mode 100644 index 0000000000..b98aa9b48c --- /dev/null +++ b/test/tsc-build/promise/parsers/clearParserCache.test.ts @@ -0,0 +1,3 @@ +import { mysqlp as mysql } from '../../index.test.js'; + +mysql.clearParserCache(); diff --git a/test/tsc-build/promise/parsers/clearParserCache.ts b/test/tsc-build/promise/parsers/clearParserCache.ts deleted file mode 100644 index 7b0ed7cec3..0000000000 --- a/test/tsc-build/promise/parsers/clearParserCache.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { mysqlp as mysql } from '../../index.js'; - -mysql.clearParserCache(); diff --git a/test/tsc-build/promise/parsers/setMaxParserCache.ts b/test/tsc-build/promise/parsers/setMaxParserCache.test.ts similarity index 66% rename from test/tsc-build/promise/parsers/setMaxParserCache.ts rename to test/tsc-build/promise/parsers/setMaxParserCache.test.ts index f6d75c8746..d5a4eef061 100644 --- a/test/tsc-build/promise/parsers/setMaxParserCache.ts +++ b/test/tsc-build/promise/parsers/setMaxParserCache.test.ts @@ -1,4 +1,4 @@ -import { mysqlp as mysql } from '../../index.js'; +import { mysqlp as mysql } from '../../index.test.js'; mysql.setMaxParserCache(1000); diff --git a/test/tsc-build/strict-checks/ProcedureCallPacket.ts b/test/tsc-build/strict-checks/ProcedureCallPacket.test.ts similarity index 94% rename from test/tsc-build/strict-checks/ProcedureCallPacket.ts rename to test/tsc-build/strict-checks/ProcedureCallPacket.test.ts index 83a7cdb0c1..02e5d7124c 100644 --- a/test/tsc-build/strict-checks/ProcedureCallPacket.ts +++ b/test/tsc-build/strict-checks/ProcedureCallPacket.test.ts @@ -1,6 +1,6 @@ -import { mysql, mysqlp } from '../index.js'; -import { access } from '../mysql/baseConnection.js'; -import { isResultSetHeader } from '../helpers.js'; +import { mysql, mysqlp } from '../index.test.js'; +import { access } from '../mysql/baseConnection.test.js'; +import { isResultSetHeader } from '../helpers.test.js'; const dropProcedure = { select: 'DROP PROCEDURE IF EXISTS selectProcedure', diff --git a/test/tsc-build/strict-checks/enableKeepAlive-and-keepAliveInitialDelay.ts b/test/tsc-build/strict-checks/enableKeepAlive-and-keepAliveInitialDelay.test.ts similarity index 91% rename from test/tsc-build/strict-checks/enableKeepAlive-and-keepAliveInitialDelay.ts rename to test/tsc-build/strict-checks/enableKeepAlive-and-keepAliveInitialDelay.test.ts index 00dfe8840d..f2708ecf67 100644 --- a/test/tsc-build/strict-checks/enableKeepAlive-and-keepAliveInitialDelay.ts +++ b/test/tsc-build/strict-checks/enableKeepAlive-and-keepAliveInitialDelay.test.ts @@ -1,16 +1,16 @@ -import { mysql, mysqlp } from '../index.js'; +import { mysql, mysqlp } from '../index.test.js'; // Callback (() => { const poolOptions: mysql.PoolOptions = { enableKeepAlive: true, keepAliveInitialDelay: 0, - } + }; const connectionOptions: mysql.ConnectionOptions = { enableKeepAlive: true, keepAliveInitialDelay: 0, - } + }; mysql.createConnection(connectionOptions); mysql.createPool(poolOptions); @@ -22,12 +22,12 @@ import { mysql, mysqlp } from '../index.js'; const poolOptions: mysqlp.PoolOptions = { enableKeepAlive: true, keepAliveInitialDelay: 0, - } + }; const connectionOptions: mysqlp.ConnectionOptions = { enableKeepAlive: true, keepAliveInitialDelay: 0, - } + }; mysqlp.createConnection(connectionOptions); mysqlp.createPool(poolOptions); diff --git a/test/tsc-build/strict-checks/execute.ts b/test/tsc-build/strict-checks/execute.test.ts similarity index 97% rename from test/tsc-build/strict-checks/execute.ts rename to test/tsc-build/strict-checks/execute.test.ts index b6b5b75580..af123f3545 100644 --- a/test/tsc-build/strict-checks/execute.ts +++ b/test/tsc-build/strict-checks/execute.test.ts @@ -3,8 +3,8 @@ * For `execute` syntax tests, please use the '../mysql' and '../promise'. */ -import { mysql, mysqlp } from '../index.js'; -import { access, sql } from '../promise/baseConnection.js'; +import { mysql, mysqlp } from '../index.test.js'; +import { access, sql } from '../promise/baseConnection.test.js'; // Callbacks { diff --git a/test/tsc-build/strict-checks/query.ts b/test/tsc-build/strict-checks/query.test.ts similarity index 97% rename from test/tsc-build/strict-checks/query.ts rename to test/tsc-build/strict-checks/query.test.ts index 82df19a7f2..780b90a73e 100644 --- a/test/tsc-build/strict-checks/query.ts +++ b/test/tsc-build/strict-checks/query.test.ts @@ -3,8 +3,8 @@ * For `query` syntax tests, please use the '../mysql' and '../promise'. */ -import { mysql, mysqlp } from '../index.js'; -import { access, sql } from '../promise/baseConnection.js'; +import { mysql, mysqlp } from '../index.test.js'; +import { access, sql } from '../promise/baseConnection.test.js'; // Callbacks { diff --git a/test/tsc-build/strict-checks/typeCast.ts b/test/tsc-build/strict-checks/typeCast.test.ts similarity index 98% rename from test/tsc-build/strict-checks/typeCast.ts rename to test/tsc-build/strict-checks/typeCast.test.ts index 0d04844100..21368f6665 100644 --- a/test/tsc-build/strict-checks/typeCast.ts +++ b/test/tsc-build/strict-checks/typeCast.test.ts @@ -3,7 +3,7 @@ import { QueryOptions as QueryOptionsP, ConnectionOptions as ConnectionOptionsP, } from '../../../promise.js'; -import { access, sql } from '../promise/baseConnection.js'; +import { access, sql } from '../promise/baseConnection.test.js'; // Callback: QueryOptions { diff --git a/test/tsc-build/tsconfig.json b/test/tsc-build/tsconfig.json index 9a4b7e1e8a..8c01d8dc9d 100644 --- a/test/tsc-build/tsconfig.json +++ b/test/tsc-build/tsconfig.json @@ -1,5 +1,11 @@ { - "include": ["index.ts", "helpers.ts", "mysql", "promise", "strict-checks"], + "include": [ + "index.test.ts", + "helpers.test.ts", + "mysql", + "promise", + "strict-checks" + ], "compilerOptions": { "target": "ES2016", "module": "CommonJS", @@ -14,6 +20,6 @@ "noEmitOnError": true, "noEmit": true, "noUnusedParameters": true, - "isolatedModules": true, + "isolatedModules": true } } diff --git a/test/unit/commands/test-query.js b/test/unit/commands/test-query.test.cjs similarity index 71% rename from test/unit/commands/test-query.js rename to test/unit/commands/test-query.test.cjs index 0aee201c45..5d0ea9e121 100644 --- a/test/unit/commands/test-query.js +++ b/test/unit/commands/test-query.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); const Query = require('../../../lib/commands/query'); const testError = new Error('something happened'); @@ -9,12 +9,12 @@ const testQuery = new Query({}, (err, res) => { assert.equal(res, null); }); -testQuery._rowParser = new class FailingRowParser { +testQuery._rowParser = new (class FailingRowParser { next() { throw testError; } -}(); +})(); testQuery.row({ - isEOF: () => false + isEOF: () => false, }); diff --git a/test/unit/commands/test-quit.js b/test/unit/commands/test-quit.js deleted file mode 100644 index ad3e8e7d82..0000000000 --- a/test/unit/commands/test-quit.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const Quit = require('../../../lib/commands/quit'); - -const testCallback = err => console.info( err.message ); -const testQuit = new Quit( testCallback ); - -assert.strictEqual( testQuit.onResult, testCallback ); diff --git a/test/unit/commands/test-quit.test.cjs b/test/unit/commands/test-quit.test.cjs new file mode 100644 index 0000000000..05ab8efa87 --- /dev/null +++ b/test/unit/commands/test-quit.test.cjs @@ -0,0 +1,9 @@ +'use strict'; + +const { assert } = require('poku'); +const Quit = require('../../../lib/commands/quit'); + +const testCallback = (err) => console.info(err.message); +const testQuit = new Quit(testCallback); + +assert.strictEqual(testQuit.onResult, testCallback); diff --git a/test/unit/connection/test-connection_config.js b/test/unit/connection/test-connection_config.test.cjs similarity index 87% rename from test/unit/connection/test-connection_config.js rename to test/unit/connection/test-connection_config.test.cjs index 8ab385b3b1..6eea4f0cc5 100644 --- a/test/unit/connection/test-connection_config.js +++ b/test/unit/connection/test-connection_config.test.cjs @@ -1,45 +1,45 @@ 'use strict'; -const ConnectionConfig = require('../../../lib/connection_config'); +const ConnectionConfig = require('../../../lib/connection_config.js'); -const assert = require('assert'); +const { assert } = require('poku'); const expectedMessage = "SSL profile must be an object, instead it's a boolean"; assert.throws( () => new ConnectionConfig({ - ssl: true + ssl: true, }), - err => err instanceof TypeError && err.message === expectedMessage, - 'Error, the constructor accepts a boolean without throwing the right exception' + (err) => err instanceof TypeError && err.message === expectedMessage, + 'Error, the constructor accepts a boolean without throwing the right exception', ); assert.doesNotThrow( () => new ConnectionConfig({ - ssl: {} + ssl: {}, }), - 'Error, the constructor accepts an object but throws an exception' + 'Error, the constructor accepts an object but throws an exception', ); assert.doesNotThrow(() => { const SSLProfiles = require('../../../lib/constants/ssl_profiles.js'); const sslProfile = Object.keys(SSLProfiles)[0]; new ConnectionConfig({ - ssl: sslProfile + ssl: sslProfile, }); }, 'Error, the constructor accepts a string but throws an exception'); assert.doesNotThrow(() => { new ConnectionConfig({ - flags: '-FOUND_ROWS' + flags: '-FOUND_ROWS', }); }, 'Error, the constructor threw an exception due to a flags string'); assert.doesNotThrow(() => { new ConnectionConfig({ - flags: ['-FOUND_ROWS'] + flags: ['-FOUND_ROWS'], }); }, 'Error, the constructor threw an exception due to a flags array'); @@ -77,4 +77,3 @@ assert.strictEqual( ).database, 'database$', ); - diff --git a/test/unit/packets/test-column-definition.js b/test/unit/packets/test-column-definition.test.cjs similarity index 88% rename from test/unit/packets/test-column-definition.js rename to test/unit/packets/test-column-definition.test.cjs index ec91f2636d..1edf9c05fb 100644 --- a/test/unit/packets/test-column-definition.js +++ b/test/unit/packets/test-column-definition.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); const ColumnDefinition = require('../../../lib/packets/column_definition.js'); const sequenceId = 5; @@ -19,13 +19,13 @@ let packet = ColumnDefinition.toPacket( columnLength: 500, flags: 32896, columnType: 0x8, - decimals: 1 + decimals: 1, }, - sequenceId + sequenceId, ); assert.equal( packet.buffer.toString('hex', 4), - '0364656607736f6d655f646208736f6d655f74626c08736f6d655f74626c08736f6d655f636f6c08736f6d655f636f6c0c2100f4010000088080010000' + '0364656607736f6d655f646208736f6d655f74626c08736f6d655f74626c08736f6d655f636f6c08736f6d655f636f6c0c2100f4010000088080010000', ); // Russian @@ -41,13 +41,13 @@ packet = ColumnDefinition.toPacket( columnLength: 500, flags: 32896, columnType: 0x8, - decimals: 1 + decimals: 1, }, - sequenceId + sequenceId, ); assert.equal( packet.buffer.toString('hex', 4), - '036465660e735fd0bfd0bed0b3d0bed0b4d0b80e745fd0bfd0bed0b3d0bed0b4d0b80f6f745fd0bfd0bed0b3d0bed0b4d0b80e6e5fd0bfd0bed0b3d0bed0b4d0b80f6f6e5fd0bfd0bed0b3d0bed0b4d0b80c2100f4010000088080010000' + '036465660e735fd0bfd0bed0b3d0bed0b4d0b80e745fd0bfd0bed0b3d0bed0b4d0b80f6f745fd0bfd0bed0b3d0bed0b4d0b80e6e5fd0bfd0bed0b3d0bed0b4d0b80f6f6e5fd0bfd0bed0b3d0bed0b4d0b80c2100f4010000088080010000', ); // Spec (from example: https://dev.mysql.com/doc/internals/en/protocoltext-resultset.html) @@ -65,16 +65,16 @@ const inputColDef = { columnType: 0xfd, type: 0xfd, encoding: 'latin1', - decimals: 0x1f -} + decimals: 0x1f, +}; packet = ColumnDefinition.toPacket(inputColDef, sequenceId); assert.equal( packet.buffer.toString('hex', 4), - '0364656600000011404076657273696f6e5f636f6d6d656e74000c08001c000000fd00001f0000' + '0364656600000011404076657273696f6e5f636f6d6d656e74000c08001c000000fd00001f0000', ); packet.offset = 4; -const colDef = new ColumnDefinition(packet, "utf8"); +const colDef = new ColumnDefinition(packet, 'utf8'); // inspect omits the "colulumnType" property because type is an alias for it // but ColumnDefinition.toPacket reads type from "columnType" // TODO: think how to make this more consistent diff --git a/test/unit/packets/test-datetime.js b/test/unit/packets/test-datetime.test.cjs similarity index 94% rename from test/unit/packets/test-datetime.js rename to test/unit/packets/test-datetime.test.cjs index 26f27f5571..7be052c4aa 100644 --- a/test/unit/packets/test-datetime.js +++ b/test/unit/packets/test-datetime.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); const packets = require('../../../lib/packets/index.js'); let buf = Buffer.from('0a000004000007dd070116010203', 'hex'); @@ -13,7 +13,7 @@ assert.equal(+d, 1358816523000); buf = Buffer.from( '18000006000004666f6f310be00702090f01095d7f06000462617231', - 'hex' + 'hex', ); packet = new packets.Packet(6, buf, 0, buf.length); diff --git a/test/unit/packets/test-ok-autoinc.js b/test/unit/packets/test-ok-autoinc.test.cjs similarity index 62% rename from test/unit/packets/test-ok-autoinc.js rename to test/unit/packets/test-ok-autoinc.test.cjs index d1c3e00c46..7a86631a44 100644 --- a/test/unit/packets/test-ok-autoinc.js +++ b/test/unit/packets/test-ok-autoinc.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); const packets = require('../../../lib/packets/index.js'); const packet = packets.OK.toPacket({ affectedRows: 0, insertId: 1 }); @@ -9,6 +9,8 @@ const packet = packets.OK.toPacket({ affectedRows: 0, insertId: 1 }); assert.equal( packet.length(), 11, - `${'OK packets with 0 affectedRows and a minimal insertId should be ' + - '11 bytes long, got '}${packet.length()} byte(s)` + `${ + 'OK packets with 0 affectedRows and a minimal insertId should be ' + + '11 bytes long, got ' + }${packet.length()} byte(s)`, ); diff --git a/test/unit/packets/test-ok-sessiontrack.js b/test/unit/packets/test-ok-sessiontrack.test.cjs similarity index 70% rename from test/unit/packets/test-ok-sessiontrack.js rename to test/unit/packets/test-ok-sessiontrack.test.cjs index 557b3f7344..84d7f5c124 100644 --- a/test/unit/packets/test-ok-sessiontrack.js +++ b/test/unit/packets/test-ok-sessiontrack.test.cjs @@ -1,19 +1,20 @@ 'use strict'; -const assert = require('assert'); -const Packet = require('../../../lib/packets/packet'); +const { assert } = require('poku'); +const Packet = require('../../../lib/packets/packet.js'); const ResultSetHeader = require('../../../lib/packets/resultset_header.js'); -const clientConstants = require('../../../lib/constants/client'); +const clientConstants = require('../../../lib/constants/client.js'); const mockConnection = { config: {}, serverEncoding: 'utf8', _handshakePacket: { - capabilityFlags: clientConstants.PROTOCOL_41 + clientConstants.SESSION_TRACK - } + capabilityFlags: + clientConstants.PROTOCOL_41 + clientConstants.SESSION_TRACK, + }, }; -const mkpacket = str => { +const mkpacket = (str) => { const buf = Buffer.from(str.split(/[ \n]+/).join(''), 'hex'); return new Packet(0, buf, 0, buf.length); }; @@ -23,16 +24,16 @@ const mkpacket = str => { assert.doesNotThrow(() => { const packet = mkpacket( `1b 00 00 01 - 00 + 00 01 fe 65 96 fc 02 00 00 00 00 03 40 00 00 00 0a 14 08 fe 60 63 9b 05 00 00 00 - ` + `, ); new ResultSetHeader(packet, mockConnection); }); assert.doesNotThrow(() => { const packet = mkpacket( - `13 00 00 01 00 01 00 02 40 00 00 00 0a 14 08 fe 18 25 e7 06 00 00 00` + `13 00 00 01 00 01 00 02 40 00 00 00 0a 14 08 fe 18 25 e7 06 00 00 00`, ); new ResultSetHeader(packet, mockConnection); }); diff --git a/test/unit/packets/test-text-row.js b/test/unit/packets/test-text-row.test.cjs similarity index 85% rename from test/unit/packets/test-text-row.js rename to test/unit/packets/test-text-row.test.cjs index e08b5f20c3..be371caa44 100644 --- a/test/unit/packets/test-text-row.js +++ b/test/unit/packets/test-text-row.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); const TextRow = require('../../../lib/packets/text_row.js'); // simple @@ -11,17 +11,17 @@ assert.equal(packet.buffer.toString('hex', 4), '0548656c6c6f05576f726c64'); packet = TextRow.toPacket(['Ну,', 'погоди!'], 'cesu8'); assert.equal( packet.buffer.toString('hex', 4), - '05d09dd1832c0dd0bfd0bed0b3d0bed0b4d0b821' + '05d09dd1832c0dd0bfd0bed0b3d0bed0b4d0b821', ); // Long > 256 byte packet = TextRow.toPacket( [ - 'Пушкин родился 26 мая (6 июня) 1799 г. в Москве. В метрической книге церкви Богоявления в Елохове (сейчас на её месте находится Богоявленский собор в Елохове) на дату 8 июня 1799 г.' + 'Пушкин родился 26 мая (6 июня) 1799 г. в Москве. В метрической книге церкви Богоявления в Елохове (сейчас на её месте находится Богоявленский собор в Елохове) на дату 8 июня 1799 г.', ], - 'cesu8' + 'cesu8', ); assert.equal( packet.buffer.toString('hex', 4), - 'fc3801d09fd183d188d0bad0b8d0bd20d180d0bed0b4d0b8d0bbd181d18f20323620d0bcd0b0d18f20283620d0b8d18ed0bdd18f29203137393920d0b32e20d0b220d09cd0bed181d0bad0b2d0b52e20d09220d0bcd0b5d182d180d0b8d187d0b5d181d0bad0bed0b920d0bad0bdd0b8d0b3d0b520d186d0b5d180d0bad0b2d0b820d091d0bed0b3d0bed18fd0b2d0bbd0b5d0bdd0b8d18f20d0b220d095d0bbd0bed185d0bed0b2d0b52028d181d0b5d0b9d187d0b0d18120d0bdd0b020d0b5d19120d0bcd0b5d181d182d0b520d0bdd0b0d185d0bed0b4d0b8d182d181d18f20d091d0bed0b3d0bed18fd0b2d0bbd0b5d0bdd181d0bad0b8d0b920d181d0bed0b1d0bed18020d0b220d095d0bbd0bed185d0bed0b2d0b52920d0bdd0b020d0b4d0b0d182d183203820d0b8d18ed0bdd18f203137393920d0b32e' + 'fc3801d09fd183d188d0bad0b8d0bd20d180d0bed0b4d0b8d0bbd181d18f20323620d0bcd0b0d18f20283620d0b8d18ed0bdd18f29203137393920d0b32e20d0b220d09cd0bed181d0bad0b2d0b52e20d09220d0bcd0b5d182d180d0b8d187d0b5d181d0bad0bed0b920d0bad0bdd0b8d0b3d0b520d186d0b5d180d0bad0b2d0b820d091d0bed0b3d0bed18fd0b2d0bbd0b5d0bdd0b8d18f20d0b220d095d0bbd0bed185d0bed0b2d0b52028d181d0b5d0b9d187d0b0d18120d0bdd0b020d0b5d19120d0bcd0b5d181d182d0b520d0bdd0b0d185d0bed0b4d0b8d182d181d18f20d091d0bed0b3d0bed18fd0b2d0bbd0b5d0bdd181d0bad0b8d0b920d181d0bed0b1d0bed18020d0b220d095d0bbd0bed185d0bed0b2d0b52920d0bdd0b020d0b4d0b0d182d183203820d0b8d18ed0bdd18f203137393920d0b32e', ); diff --git a/test/unit/packets/test-time.js b/test/unit/packets/test-time.test.cjs similarity index 87% rename from test/unit/packets/test-time.js rename to test/unit/packets/test-time.test.cjs index 2f9a1dfd66..f3febefb7a 100644 --- a/test/unit/packets/test-time.js +++ b/test/unit/packets/test-time.test.cjs @@ -1,6 +1,6 @@ 'use strict'; -const assert = require('assert'); +const { assert } = require('poku'); const packets = require('../../../lib/packets/index.js'); [ @@ -11,7 +11,7 @@ const packets = require('../../../lib/packets/index.js'); ['81:23:45', '0b000004000008000300000009172d'], // CONVERT('81:23:45', TIME) ['123:23:45.123456', '0f00000400000c000500000003172d40e20100'], // DATE_ADD(CONVERT('123:23:45', TIME), INTERVAL 0.123456 SECOND) ['-121:23:45', '0b000004000008010500000001172d'], // CONVERT('-121:23:45', TIME) - ['-01:23:44.88', '0f00000400000c010000000001172c806d0d00'] //DATE_ADD(CONVERT('-01:23:45', TIME), INTERVAL 0.12 SECOND) + ['-01:23:44.88', '0f00000400000c010000000001172c806d0d00'], //DATE_ADD(CONVERT('-01:23:45', TIME), INTERVAL 0.12 SECOND) ].forEach(([expected, buffer]) => { const buf = Buffer.from(buffer, 'hex'); const packet = new packets.Packet(4, buf, 0, buf.length); diff --git a/test/unit/parsers/test-text-parser.js b/test/unit/parsers/test-text-parser.test.cjs similarity index 52% rename from test/unit/parsers/test-text-parser.js rename to test/unit/parsers/test-text-parser.test.cjs index 01d77c1109..83465e3402 100644 --- a/test/unit/parsers/test-text-parser.js +++ b/test/unit/parsers/test-text-parser.test.cjs @@ -1,7 +1,7 @@ 'use strict'; -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const typeCastWrapper = function (...args) { return function (field, next) { @@ -10,29 +10,35 @@ const typeCastWrapper = function (...args) { } return next(); - } -} + }; +}; const connection = common.createConnection(); connection.query('CREATE TEMPORARY TABLE t (i JSON)'); connection.query('INSERT INTO t values(\'{ "test": "😀" }\')'); // JSON without encoding options - should result in unexpected behaviors -connection.query({ - sql: 'SELECT * FROM t', - typeCast: typeCastWrapper() -}, (err, rows) => { - assert.ifError(err); - assert.notEqual(rows[0].i.test, "😀"); -}); +connection.query( + { + sql: 'SELECT * FROM t', + typeCast: typeCastWrapper(), + }, + (err, rows) => { + assert.ifError(err); + assert.notEqual(rows[0].i.test, '😀'); + }, +); // JSON with encoding explicitly set to utf8 -connection.query({ - sql: 'SELECT * FROM t', - typeCast: typeCastWrapper("utf8") -}, (err, rows) => { - assert.ifError(err); - assert.equal(rows[0].i.test, "😀"); -}); +connection.query( + { + sql: 'SELECT * FROM t', + typeCast: typeCastWrapper('utf8'), + }, + (err, rows) => { + assert.ifError(err); + assert.equal(rows[0].i.test, '😀'); + }, +); connection.end(); diff --git a/test/unit/pool-cluster/test-connection-error-remove.js b/test/unit/pool-cluster/test-connection-error-remove.test.cjs similarity index 65% rename from test/unit/pool-cluster/test-connection-error-remove.js rename to test/unit/pool-cluster/test-connection-error-remove.test.cjs index e87f478952..9ebdaaf93b 100644 --- a/test/unit/pool-cluster/test-connection-error-remove.js +++ b/test/unit/pool-cluster/test-connection-error-remove.test.cjs @@ -6,10 +6,10 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const assert = require('assert'); +const { assert } = require('poku'); const portfinder = require('portfinder'); -const common = require('../../common'); +const common = require('../../common.test.cjs'); const mysql = require('../../../index.js'); const { exit } = require('process'); @@ -19,48 +19,47 @@ if (process.platform === 'win32') { } const cluster = common.createPoolCluster({ - removeNodeErrorCount : 1 + removeNodeErrorCount: 1, }); let connCount = 0; -const server1 = mysql.createServer(); -const server2 = mysql.createServer(); +const server1 = mysql.createServer(); +const server2 = mysql.createServer(); console.log('test pool cluster error remove'); -portfinder.getPort((err,port) => { +portfinder.getPort((err, port) => { + cluster.add('SLAVE1', { port: port + 0 }); + cluster.add('SLAVE2', { port: port + 1 }); - cluster.add('SLAVE1', {port: port + 0}); - cluster.add('SLAVE2', {port: port + 1}); - - server1.listen(port + 0, err => { + server1.listen(port + 0, (err) => { assert.ifError(err); - - server2.listen(port + 1, err => { + + server2.listen(port + 1, (err) => { assert.ifError(err); - + const pool = cluster.of('*', 'ORDER'); let removedNodeId; - - cluster.on('remove', nodeId => { + + cluster.on('remove', (nodeId) => { removedNodeId = nodeId; }); - + pool.getConnection((err, connection) => { assert.ifError(err); assert.equal(connCount, 2); assert.equal(connection._clusterId, 'SLAVE2'); assert.equal(removedNodeId, 'SLAVE1'); - assert.deepEqual(cluster._serviceableNodeIds, [ 'SLAVE2' ]); - console.log('done') + assert.deepEqual(cluster._serviceableNodeIds, ['SLAVE2']); + console.log('done'); connection.release(); - cluster.end(err => { + cluster.end((err) => { assert.ifError(err); - // throw error if no exit() + // throw error if no exit() exit(); // server1.close(); // server2.close(); @@ -68,13 +67,13 @@ portfinder.getPort((err,port) => { }); }); }); - - server1.on('connection', conn => { + + server1.on('connection', (conn) => { connCount += 1; conn.close(); }); - - server2.on('connection', conn => { + + server2.on('connection', (conn) => { connCount += 1; conn.serverHandshake({ serverVersion: 'node.js rocks', diff --git a/test/unit/pool-cluster/test-connection-order.js b/test/unit/pool-cluster/test-connection-order.test.cjs similarity index 77% rename from test/unit/pool-cluster/test-connection-order.js rename to test/unit/pool-cluster/test-connection-order.test.cjs index 06946b4647..c6c5ca3a58 100644 --- a/test/unit/pool-cluster/test-connection-order.js +++ b/test/unit/pool-cluster/test-connection-order.test.cjs @@ -6,8 +6,8 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const cluster = common.createPoolCluster(); const order = []; @@ -16,14 +16,8 @@ const poolConfig = common.getConfig(); cluster.add('SLAVE1', poolConfig); cluster.add('SLAVE2', poolConfig); -const done = function() { - assert.deepEqual(order, [ - 'SLAVE1', - 'SLAVE1', - 'SLAVE1', - 'SLAVE1', - 'SLAVE1' - ]); +const done = function () { + assert.deepEqual(order, ['SLAVE1', 'SLAVE1', 'SLAVE1', 'SLAVE1', 'SLAVE1']); cluster.end(); console.log('done'); }; @@ -42,7 +36,7 @@ function getConnection(i) { count += 1; - if(count <= 4) { + if (count <= 4) { getConnection(count); } else { done(); diff --git a/test/unit/pool-cluster/test-connection-restore.js b/test/unit/pool-cluster/test-connection-restore.test.cjs similarity index 75% rename from test/unit/pool-cluster/test-connection-restore.js rename to test/unit/pool-cluster/test-connection-restore.test.cjs index dde1f9ae9c..b6d635f7a2 100644 --- a/test/unit/pool-cluster/test-connection-restore.js +++ b/test/unit/pool-cluster/test-connection-restore.test.cjs @@ -11,14 +11,14 @@ if (process.platform === 'win32') { process.exit(0); } -const assert = require('assert'); +const { assert } = require('poku'); const portfinder = require('portfinder'); -const common = require('../../common'); +const common = require('../../common.test.cjs'); const mysql = require('../../../index.js'); const cluster = common.createPoolCluster({ - canRetry : true, - removeNodeErrorCount : 1, - restoreNodeTimeout : 100 + canRetry: true, + removeNodeErrorCount: 1, + restoreNodeTimeout: 100, }); let connCount = 0; @@ -27,41 +27,41 @@ const server = mysql.createServer(); console.log('test pool cluster restore'); -portfinder.getPort((err,port) => { +portfinder.getPort((err, port) => { cluster.add('MASTER', { port }); - server.listen(port + 0, err => { + server.listen(port + 0, (err) => { assert.ifError(err); - + const pool = cluster.of('*', 'ORDER'); let removedNodeId; - cluster.on('remove', nodeId => { + cluster.on('remove', (nodeId) => { removedNodeId = nodeId; }); - pool.getConnection(err => { + pool.getConnection((err) => { assert.ok(err); - console.log(connCount, cluster._serviceableNodeIds, removedNodeId) + console.log(connCount, cluster._serviceableNodeIds, removedNodeId); }); setTimeout(() => { pool.getConnection(() => { // TODO: restoreNodeTimeout is not supported now - console.log(connCount, cluster._serviceableNodeIds, removedNodeId) + console.log(connCount, cluster._serviceableNodeIds, removedNodeId); - cluster.end(err => { + cluster.end((err) => { assert.ifError(err); server._server.close(); }); }); - }, 200) + }, 200); }); - - server.on('connection', conn => { + + server.on('connection', (conn) => { connCount += 1; console.log(connCount); - if(connCount < 2) { + if (connCount < 2) { conn.close(); } else { conn.serverHandshake({ diff --git a/test/unit/pool-cluster/test-connection-rr.js b/test/unit/pool-cluster/test-connection-rr.test.cjs similarity index 76% rename from test/unit/pool-cluster/test-connection-rr.js rename to test/unit/pool-cluster/test-connection-rr.test.cjs index 95bcbb32f7..82761c420d 100644 --- a/test/unit/pool-cluster/test-connection-rr.js +++ b/test/unit/pool-cluster/test-connection-rr.test.cjs @@ -6,8 +6,8 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { process.exit(0); } -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const cluster = common.createPoolCluster(); const order = []; @@ -16,14 +16,8 @@ const poolConfig = common.getConfig(); cluster.add('SLAVE1', poolConfig); cluster.add('SLAVE2', poolConfig); -const done = function() { - assert.deepEqual(order, [ - 'SLAVE1', - 'SLAVE2', - 'SLAVE1', - 'SLAVE2', - 'SLAVE1' - ]); +const done = function () { + assert.deepEqual(order, ['SLAVE1', 'SLAVE2', 'SLAVE1', 'SLAVE2', 'SLAVE1']); cluster.end(); console.log('done'); }; @@ -42,7 +36,7 @@ function getConnection(i) { count += 1; - if(count <= 4) { + if (count <= 4) { getConnection(count); } else { done(); @@ -50,4 +44,4 @@ function getConnection(i) { }); } -getConnection(0); \ No newline at end of file +getConnection(0); diff --git a/test/unit/pool-cluster/test-query.js b/test/unit/pool-cluster/test-query.test.cjs similarity index 80% rename from test/unit/pool-cluster/test-query.js rename to test/unit/pool-cluster/test-query.test.cjs index 6502a1e6e5..02691c82a4 100644 --- a/test/unit/pool-cluster/test-query.js +++ b/test/unit/pool-cluster/test-query.test.cjs @@ -4,14 +4,13 @@ if (`${process.env.MYSQL_CONNECTION_URL}`.includes('pscale_pw_')) { console.log('skipping test for planetscale'); process.exit(0); -} +} -const assert = require('assert'); -const common = require('../../common'); +const { assert } = require('poku'); +const common = require('../../common.test.cjs'); const cluster = common.createPoolCluster(); const poolConfig = common.getConfig(); - cluster.add('MASTER', poolConfig); cluster.add('SLAVE1', poolConfig); cluster.add('SLAVE2', poolConfig); @@ -24,7 +23,7 @@ connection.query('SELECT 1', (err, rows) => { assert.ifError(err); assert.equal(rows.length, 1); assert.equal(rows[0]['1'], 1); - assert.deepEqual(cluster._serviceableNodeIds, [ 'MASTER', 'SLAVE1', 'SLAVE2' ]) + assert.deepEqual(cluster._serviceableNodeIds, ['MASTER', 'SLAVE1', 'SLAVE2']); cluster.end(); console.log('done'); diff --git a/test/unit/protocol/test-SqlString.js b/test/unit/protocol/test-SqlString.js deleted file mode 100644 index 157bf62f5d..0000000000 --- a/test/unit/protocol/test-SqlString.js +++ /dev/null @@ -1,197 +0,0 @@ -'use strict'; - -const common = require('../../common'); -const test = require('utest'); -const assert = require('assert'); -const SqlString = common.SqlString; - -test('SqlString.escapeId', { - 'value is quoted': function() { - assert.equal('`id`', SqlString.escapeId('id')); - }, - - 'value containing escapes is quoted': function() { - assert.equal('`i``d`', SqlString.escapeId('i`d')); - }, - - 'value containing separator is quoted': function() { - assert.equal('`id1`.`id2`', SqlString.escapeId('id1.id2')); - }, - 'value containing separator and escapes is quoted': function() { - assert.equal('`id``1`.`i``d2`', SqlString.escapeId('id`1.i`d2')); - }, - - 'arrays are turned into lists': function() { - assert.equal(SqlString.escapeId(['a', 'b', 't.c']), '`a`, `b`, `t`.`c`'); - }, - - 'nested arrays are flattened': function() { - assert.equal( - SqlString.escapeId(['a', ['b', ['t.c']]]), - '`a`, `b`, `t`.`c`' - ); - } -}); - -test('SqlString.escape', { - 'undefined -> NULL': function() { - assert.equal(SqlString.escape(undefined), 'NULL'); - }, - - 'null -> NULL': function() { - assert.equal(SqlString.escape(null), 'NULL'); - }, - - 'booleans convert to strings': function() { - assert.equal(SqlString.escape(false), 'false'); - assert.equal(SqlString.escape(true), 'true'); - }, - - 'numbers convert to strings': function() { - assert.equal(SqlString.escape(5), '5'); - }, - - 'objects are turned into key value pairs': function() { - assert.equal(SqlString.escape({ a: 'b', c: 'd' }), "`a` = 'b', `c` = 'd'"); - }, - - 'objects function properties are ignored': function() { - assert.equal(SqlString.escape({ a: 'b', c: function() {} }), "`a` = 'b'"); - }, - - 'nested objects are cast to strings': function() { - assert.equal( - SqlString.escape({ a: { nested: true } }), - "`a` = '[object Object]'" - ); - }, - - 'arrays are turned into lists': function() { - assert.equal(SqlString.escape([1, 2, 'c']), "1, 2, 'c'"); - }, - - 'nested arrays are turned into grouped lists': function() { - assert.equal( - SqlString.escape([[1, 2, 3], [4, 5, 6], ['a', 'b', { nested: true }]]), - "(1, 2, 3), (4, 5, 6), ('a', 'b', '[object Object]')" - ); - }, - - 'nested objects inside arrays are cast to strings': function() { - assert.equal( - SqlString.escape([1, { nested: true }, 2]), - "1, '[object Object]', 2" - ); - }, - - 'strings are quoted': function() { - assert.equal(SqlString.escape('Super'), "'Super'"); - }, - - '\0 gets escaped': function() { - assert.equal(SqlString.escape('Sup\0er'), "'Sup\\0er'"); - }, - - '\b gets escaped': function() { - assert.equal(SqlString.escape('Sup\ber'), "'Sup\\ber'"); - }, - - '\n gets escaped': function() { - assert.equal(SqlString.escape('Sup\ner'), "'Sup\\ner'"); - }, - - '\r gets escaped': function() { - assert.equal(SqlString.escape('Sup\rer'), "'Sup\\rer'"); - }, - - '\t gets escaped': function() { - assert.equal(SqlString.escape('Sup\ter'), "'Sup\\ter'"); - }, - - '\\ gets escaped': function() { - assert.equal(SqlString.escape('Sup\\er'), "'Sup\\\\er'"); - }, - - '\u001a (ascii 26) gets replaced with \\Z': function() { - assert.equal(SqlString.escape('Sup\u001aer'), "'Sup\\Zer'"); - }, - - 'single quotes get escaped': function() { - assert.equal(SqlString.escape("Sup'er"), "'Sup\\'er'"); - }, - - 'double quotes get escaped': function() { - assert.equal(SqlString.escape('Sup"er'), "'Sup\\\"er'"); - }, - - 'dates are converted to YYYY-MM-DD HH:II:SS.sss': function() { - const expected = '2012-05-07 11:42:03.002'; - const date = new Date(2012, 4, 7, 11, 42, 3, 2); - const string = SqlString.escape(date); - - assert.strictEqual(string, `'${expected}'`); - }, - - 'buffers are converted to hex': function() { - const buffer = Buffer.from([0, 1, 254, 255]); - const string = SqlString.escape(buffer); - - assert.strictEqual(string, "X'0001feff'"); - }, - - 'NaN -> NaN': function() { - assert.equal(SqlString.escape(NaN), 'NaN'); - }, - - 'Infinity -> Infinity': function() { - assert.equal(SqlString.escape(Infinity), 'Infinity'); - } -}); - -test('SqlString.format', { - 'question marks are replaced with escaped array values': function() { - const sql = SqlString.format('? and ?', ['a', 'b']); - assert.equal(sql, "'a' and 'b'"); - }, - - 'extra question marks are left untouched': function() { - const sql = SqlString.format('? and ?', ['a']); - assert.equal(sql, "'a' and ?"); - }, - - 'extra arguments are not used': function() { - const sql = SqlString.format('? and ?', ['a', 'b', 'c']); - assert.equal(sql, "'a' and 'b'"); - }, - - 'question marks within values do not cause issues': function() { - const sql = SqlString.format('? and ?', ['hello?', 'b']); - assert.equal(sql, "'hello?' and 'b'"); - }, - - 'undefined is ignored': function() { - const sql = SqlString.format('?', undefined, false); - assert.equal(sql, '?'); - }, - - 'objects is converted to values': function() { - const sql = SqlString.format('?', { hello: 'world' }, false); - assert.equal(sql, "`hello` = 'world'"); - }, - - 'objects is not converted to values': function() { - const sql = SqlString.format('?', { hello: 'world' }, true); - assert.equal(sql, "'[object Object]'"); - - const sql2 = SqlString.format( - '?', - { - toString: function() { - return 'hello'; - } - }, - true - ); - assert.equal(sql2, "'hello'"); - } -}); diff --git a/test/unit/test-Pool.js b/test/unit/test-Pool.js deleted file mode 100644 index 093edb3c32..0000000000 --- a/test/unit/test-Pool.js +++ /dev/null @@ -1,65 +0,0 @@ -'use strict'; - -const mysql = require('../..'); -const test = require('utest'); -const assert = require('assert'); - -const poolConfig = {}; // config: { connectionConfig: {} } }; - -const pool = new mysql.createPool(poolConfig); -test('Pool', { - 'exposes escape': () => { - assert.equal(pool.escape(123), '123'); - }, - - 'exposes escapeId': () => { - assert.equal(pool.escapeId('table name'), '`table name`'); - }, - - 'exposes format': () => { - const params = ['table name', 'thing']; - assert.equal( - pool.format('SELECT a FROM ?? WHERE b = ?', params), - "SELECT a FROM `table name` WHERE b = 'thing'" - ); - } -}); - -const poolDotPromise = pool.promise(); -test('Pool.promise()', { - 'exposes escape': () => { - assert.equal(poolDotPromise.escape(123), '123'); - }, - - 'exposes escapeId': () => { - assert.equal(poolDotPromise.escapeId('table name'), '`table name`'); - }, - - 'exposes format': () => { - const params = ['table name', 'thing']; - assert.equal( - poolDotPromise.format('SELECT a FROM ?? WHERE b = ?', params), - "SELECT a FROM `table name` WHERE b = 'thing'" - ); - } -}); - -const promisePool = new mysql.createPoolPromise(poolConfig); -// REVIEW! -test('PromisePool', { - 'exposes escape': () => { - assert.equal(promisePool.escape(123), '123'); - }, - - 'exposes escapeId': () => { - assert.equal(promisePool.escapeId('table name'), '`table name`'); - }, - - 'exposes format': () => { - const params = ['table name', 'thing']; - assert.equal( - promisePool.format('SELECT a FROM ?? WHERE b = ?', params), - "SELECT a FROM `table name` WHERE b = 'thing'" - ); - } -}); diff --git a/test/unit/test-packet-parser.js b/test/unit/test-packet-parser.test.cjs similarity index 89% rename from test/unit/test-packet-parser.js rename to test/unit/test-packet-parser.test.cjs index 1a0cbb04dc..09956f57b3 100644 --- a/test/unit/test-packet-parser.js +++ b/test/unit/test-packet-parser.test.cjs @@ -3,11 +3,11 @@ const PacketParser = require('../../lib/packet_parser.js'); const Packet = require('../../lib/packets/packet.js'); -const assert = require('assert'); +const { assert } = require('poku'); let pp; let packets = []; -const handler = function(p) { +const handler = function (p) { packets.push(p); }; function reset() { @@ -17,7 +17,7 @@ function reset() { function execute(str, verify) { reset(); - const buffers = str.split('|').map(sb => sb.split(',').map(Number)); + const buffers = str.split('|').map((sb) => sb.split(',').map(Number)); for (let i = 0; i < buffers.length; ++i) { pp.execute(Buffer.from(buffers[i])); } @@ -31,7 +31,7 @@ function p123() { } function p120_121() { - packets.forEach(p => { + packets.forEach((p) => { p.dump; }); assert(packets.length === 2); @@ -66,7 +66,7 @@ execute('0|0,0|42', p42); execute('0,0,0,120,0,0,0,121', p120_121); execute('0,0,0|120|0|0|0|121', p120_121); -const p122_123 = function() { +const p122_123 = function () { assert(packets.length === 2); assert(packets[0].length() === 9); assert(packets[0].sequenceId === 122); @@ -97,10 +97,10 @@ p.writeHeader(42); function testBigPackets(chunks, cb) { const packets = []; - const pp = new PacketParser(p => { + const pp = new PacketParser((p) => { packets.push(p); }); - chunks.forEach(ch => { + chunks.forEach((ch) => { pp.execute(ch); }); cb(packets); @@ -126,22 +126,22 @@ testBigPackets([pbuff, pbuff], assert2FullPackets); testBigPackets( [pbuff.slice(0, 120000), pbuff.slice(120000, 123004), pbuff], - assert2FullPackets + assert2FullPackets, ); const frameEnd = 120000; testBigPackets( [ pbuff.slice(0, frameEnd), - Buffer.concat([pbuff.slice(frameEnd, 123004), pbuff]) + Buffer.concat([pbuff.slice(frameEnd, 123004), pbuff]), ], - assert2FullPackets + assert2FullPackets, ); for (let frameStart = 1; frameStart < 100; frameStart++) { testBigPackets( [ Buffer.concat([pbuff, pbuff.slice(0, frameStart)]), - pbuff.slice(frameStart, 123004) + pbuff.slice(frameStart, 123004), ], - assert2FullPackets + assert2FullPackets, ); } diff --git a/tools/create-db.js b/tools/create-db.js index 4d28aabcd7..2e1d677150 100644 --- a/tools/create-db.js +++ b/tools/create-db.js @@ -1,6 +1,6 @@ 'use strict'; -const conn = require('../test/common.js').createConnection({ database: 'mysql' }); +const conn = require('../test/common.test.cjs').createConnection({ database: 'mysql' }); conn.query('CREATE DATABASE IF NOT EXISTS test', err => { if (err) { console.log(err); diff --git a/tools/wait-up.js b/tools/wait-up.js index 27c00be4d2..235a9e76c5 100644 --- a/tools/wait-up.js +++ b/tools/wait-up.js @@ -1,5 +1,5 @@ 'use strict'; -require('../test/common.js').waitDatabaseReady(() => { +require('../test/common.test.cjs').waitDatabaseReady(() => { console.log('ready!'); }); diff --git a/typings/mysql/index.d.ts b/typings/mysql/index.d.ts index b7fd83a90c..7dafa9cbf3 100644 --- a/typings/mysql/index.d.ts +++ b/typings/mysql/index.d.ts @@ -62,14 +62,14 @@ export function format( sql: string, values: any[], stringifyObjects?: boolean, - timeZone?: string + timeZone?: string, ): string; export function format( sql: string, values: any, stringifyObjects?: boolean, - timeZone?: string + timeZone?: string, ): string; export function raw(sql: string): { diff --git a/typings/mysql/lib/Auth.d.ts b/typings/mysql/lib/Auth.d.ts index bfb32bdba6..13374a9485 100644 --- a/typings/mysql/lib/Auth.d.ts +++ b/typings/mysql/lib/Auth.d.ts @@ -5,7 +5,7 @@ export type AuthPlugin = (pluginMetadata: { connection: Connection; command: string; }) => ( - pluginData: Buffer + pluginData: Buffer, ) => Promise | string | Buffer | Promise | null; type AuthPluginDefinition = (pluginOptions?: T) => AuthPlugin; diff --git a/typings/mysql/lib/Pool.d.ts b/typings/mysql/lib/Pool.d.ts index 90ed5e9bad..042495e71f 100644 --- a/typings/mysql/lib/Pool.d.ts +++ b/typings/mysql/lib/Pool.d.ts @@ -43,14 +43,14 @@ declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) { getConnection( callback: ( err: NodeJS.ErrnoException | null, - connection: PoolConnection - ) => any + connection: PoolConnection, + ) => any, ): void; releaseConnection(connection: PoolConnection | PromisePoolConnection): void; end( - callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any + callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any, ): void; on(event: string, listener: (...args: any[]) => void): this; diff --git a/typings/mysql/lib/PoolCluster.d.ts b/typings/mysql/lib/PoolCluster.d.ts index 476d3de493..2be0be860c 100644 --- a/typings/mysql/lib/PoolCluster.d.ts +++ b/typings/mysql/lib/PoolCluster.d.ts @@ -6,7 +6,7 @@ import { QueryableBase as QueryableBaseClass } from './protocol/sequences/Querya // Expose class interfaces declare class QueryableAndExecutableBase extends QueryableBaseClass( - ExecutableBaseClass(EventEmitter) + ExecutableBaseClass(EventEmitter), ) {} export interface PoolClusterOptions { @@ -40,8 +40,8 @@ export interface PoolNamespace extends QueryableAndExecutableBase { getConnection( callback: ( err: NodeJS.ErrnoException | null, - connection: PoolConnection - ) => any + connection: PoolConnection, + ) => any, ): void; } @@ -57,23 +57,23 @@ declare class PoolCluster extends EventEmitter { getConnection( callback: ( err: NodeJS.ErrnoException | null, - connection: PoolConnection - ) => void + connection: PoolConnection, + ) => void, ): void; getConnection( group: string, callback: ( err: NodeJS.ErrnoException | null, - connection: PoolConnection - ) => void + connection: PoolConnection, + ) => void, ): void; getConnection( group: string, selector: string, callback: ( err: NodeJS.ErrnoException | null, - connection: PoolConnection - ) => void + connection: PoolConnection, + ) => void, ): void; of(pattern: string, selector?: string): PoolNamespace; diff --git a/typings/mysql/lib/protocol/packets/FieldPacket.d.ts b/typings/mysql/lib/protocol/packets/FieldPacket.d.ts index 316c44ed77..7e886691ef 100644 --- a/typings/mysql/lib/protocol/packets/FieldPacket.d.ts +++ b/typings/mysql/lib/protocol/packets/FieldPacket.d.ts @@ -17,7 +17,7 @@ declare interface FieldPacket { protocol41?: boolean; table: string; type?: number; - columnType?: number + columnType?: number; zerofill?: boolean; typeName?: string; encoding?: string; diff --git a/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts b/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts index 47e51fd4b5..ff5efb63ed 100644 --- a/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts +++ b/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts @@ -7,7 +7,7 @@ declare type ProcedureCallPacket< > = T extends RowDataPacket[] ? [T, ResultSetHeader] : T extends ResultSetHeader | OkPacket - ? ResultSetHeader - : [RowDataPacket[], ResultSetHeader] | ResultSetHeader; + ? ResultSetHeader + : [RowDataPacket[], ResultSetHeader] | ResultSetHeader; export { ProcedureCallPacket }; diff --git a/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts b/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts index 5242b03a70..ba37c2efe1 100644 --- a/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts +++ b/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts @@ -1,7 +1,4 @@ -import { - FieldPacket, - QueryResult, -} from '../packets/index.js'; +import { FieldPacket, QueryResult } from '../packets/index.js'; import { Query, QueryError, @@ -10,34 +7,34 @@ import { } from './Query.js'; export declare function ExecutableBase( - Base?: T + Base?: T, ): { new (...args: any[]): { execute( sql: string, callback?: | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any) - | undefined + | undefined, ): Query; execute( sql: string, values: any, callback?: | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any) - | undefined + | undefined, ): Query; execute( options: QueryOptions, callback?: | ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any) - | undefined + | undefined, ): Query; execute( options: QueryOptions, values: any, callback?: | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any) - | undefined + | undefined, ): Query; }; } & T; diff --git a/typings/mysql/lib/protocol/sequences/Prepare.d.ts b/typings/mysql/lib/protocol/sequences/Prepare.d.ts index ef13801611..bdd91a0930 100644 --- a/typings/mysql/lib/protocol/sequences/Prepare.d.ts +++ b/typings/mysql/lib/protocol/sequences/Prepare.d.ts @@ -16,10 +16,14 @@ export class PrepareStatementInfo { | RowDataPacket[] | OkPacket | OkPacket[] - | ResultSetHeader + | ResultSetHeader, >( parameters: any | any[] | { [param: string]: any }, - callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any + callback?: ( + err: QueryError | null, + result: T, + fields: FieldPacket[], + ) => any, ): Query; } @@ -53,11 +57,11 @@ declare class Prepare extends Sequence { on(event: 'error', listener: (err: QueryError) => any): this; on( event: 'fields', - listener: (fields: FieldPacket, index: number) => any + listener: (fields: FieldPacket, index: number) => any, ): this; on( event: 'result', - listener: (result: RowDataPacket | OkPacket, index: number) => any + listener: (result: RowDataPacket | OkPacket, index: number) => any, ): this; on(event: 'end', listener: () => any): this; } diff --git a/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts b/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts index 935d948229..2c2060d285 100644 --- a/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts +++ b/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts @@ -1,7 +1,4 @@ -import { - FieldPacket, - QueryResult, -} from '../packets/index.js'; +import { FieldPacket, QueryResult } from '../packets/index.js'; import { Query, QueryError, @@ -10,34 +7,34 @@ import { } from './Query.js'; export declare function QueryableBase( - Base?: T + Base?: T, ): { new (...args: any[]): { query( sql: string, callback?: | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any) - | undefined + | undefined, ): Query; query( sql: string, values: any, callback?: | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any) - | undefined + | undefined, ): Query; query( options: QueryOptions, callback?: | ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any) - | undefined + | undefined, ): Query; query( options: QueryOptions, values: any, callback?: | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any) - | undefined + | undefined, ): Query; }; } & T; diff --git a/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts b/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts index 17de50b8be..aec027b5ae 100644 --- a/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts +++ b/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts @@ -1,26 +1,21 @@ -import { - FieldPacket, - QueryResult, -} from '../../packets/index.js'; +import { FieldPacket, QueryResult } from '../../packets/index.js'; import { QueryOptions, QueryableConstructor } from '../Query.js'; export declare function ExecutableBase( - Base?: T + Base?: T, ): { new (...args: any[]): { - execute( - sql: string - ): Promise<[T, FieldPacket[]]>; + execute(sql: string): Promise<[T, FieldPacket[]]>; execute( sql: string, - values: any + values: any, ): Promise<[T, FieldPacket[]]>; execute( - options: QueryOptions + options: QueryOptions, ): Promise<[T, FieldPacket[]]>; execute( options: QueryOptions, - values: any + values: any, ): Promise<[T, FieldPacket[]]>; }; } & T; diff --git a/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts b/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts index c578627cb1..0240431041 100644 --- a/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts +++ b/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts @@ -1,26 +1,21 @@ -import { - FieldPacket, - QueryResult, -} from '../../packets/index.js'; +import { FieldPacket, QueryResult } from '../../packets/index.js'; import { QueryOptions, QueryableConstructor } from '../Query.js'; export declare function QueryableBase( - Base?: T + Base?: T, ): { new (...args: any[]): { - query( - sql: string - ): Promise<[T, FieldPacket[]]>; + query(sql: string): Promise<[T, FieldPacket[]]>; query( sql: string, - values: any + values: any, ): Promise<[T, FieldPacket[]]>; query( - options: QueryOptions + options: QueryOptions, ): Promise<[T, FieldPacket[]]>; query( options: QueryOptions, - values: any + values: any, ): Promise<[T, FieldPacket[]]>; }; } & T; diff --git a/website/test/unit/check-extensions.test.ts b/website/test/unit/check-extensions.test.ts index 5b63c468cb..d2e51ba21a 100644 --- a/website/test/unit/check-extensions.test.ts +++ b/website/test/unit/check-extensions.test.ts @@ -3,8 +3,7 @@ import { listFiles, assert } from 'poku'; const invalidFiles: string[] = []; const message = [ - 'Invalid file types found in restricted directories.', - 'Please ensure that files in these directories have one of the following extensions:', + 'Check for invalid file types found in restricted directories', ]; const checkExtensions = (