Skip to content

Commit

Permalink
test: Relace mocha/chai by Node.js test runner and asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaumgartl committed Jun 11, 2024
1 parent d121f48 commit 2ff08c7
Show file tree
Hide file tree
Showing 25 changed files with 934 additions and 1,100 deletions.
10 changes: 1 addition & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@
},
"parserOptions": {
"ecmaVersion": 2022
},
"overrides": [
{
"files": ["test/**/*.js"],
"env": {
"mocha": true
}
}
]
}
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function hasSqlEquivalent(attribute, columns) {
function checkSqlEquivalents(attributes, columns) {
attributes.forEach((attribute) => {
if (!hasSqlEquivalent(attribute, columns)) {
throw new Error('Attribute "' + attribute + '" is not provided by SQL query');
throw new ImplementationError('Attribute "' + attribute + '" is not provided by SQL query');
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion lib/sql-query-checker.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

const { ImplementationError } = require('@florajs/errors');

function isColumn(expr) {
return Object.hasOwn(expr, 'type') && expr.type === 'column_ref';
}

function checkColumn(expr) {
if (expr.table !== null) return;
throw new Error(`Column "${expr.column}" must be fully qualified`);
throw new ImplementationError(`Column "${expr.column}" must be fully qualified`);
}

/**
Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"test:start-testdb": "docker run -d --name flora-mysql-testdb -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=${MYSQL_DATABASE:-flora_mysql_testdb} -p ${MYSQL_PORT:-3306}:3306 --mount type=bind,src=\"$PWD/test/integration/fixtures\",target=/docker-entrypoint-initdb.d,readonly --tmpfs \"/var/lib/mysql\" mysql:${MYSQL_VERSION:-8.0}",
"test:mysql": "./test/integration/tool/wait-for-mysql.sh ${MYSQL_HOST:-localhost} ${MYSQL_PORT:-3306} ${MYSQL_DATABASE:-flora_mysql_testdb} && npm run test:ci",
"test:stop": "docker stop flora-mysql-testdb",
"test:ci": "mocha test/integration/*.spec.js",
"test:ci": "node --test test/integration/*.spec.js",
"test-ci": "npm run test:cleanup; npm run test:start-testdb && npm run test:mysql; npm run test:stop",
"test-unit": "mocha test/unit/*.spec.js test/unit/**/*.spec.js",
"test-unit": "node --test test/unit/*.spec.js test/unit/**/*.spec.js",
"test": "npm run test-unit && npm run test-ci",
"lint": "eslint ."
},
Expand Down Expand Up @@ -54,13 +54,9 @@
},
"devDependencies": {
"bunyan": "^1.8.15",
"chai": "^4.3.7",
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^5.0.0",
"mocha": "^10.2.0",
"prettier": "^3.0.1",
"sinon": "^15.2.0",
"sinon-chai": "^3.7.0"
"prettier": "^3.0.1"
}
}
8 changes: 4 additions & 4 deletions test/ast-tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module.exports = {
options: null,
distinct: null,
columns: [
{ expr: { type: 'column_ref', table: 't', column: 'id' }, as: null },
{ expr: { type: 'column_ref', table: 't', column: 'col1' }, as: null },
{ expr: { type: 'column_ref', table: 't', column: 'col2' }, as: null }
{ expr: { type: 'column_ref', table: 'flora_request_processing', column: 'id' }, as: null },
{ expr: { type: 'column_ref', table: 'flora_request_processing', column: 'col1' }, as: null },
{ expr: { type: 'column_ref', table: 'flora_request_processing', column: 'col2' }, as: null }
],
from: [{ db: null, table: 't', as: null }],
from: [{ db: null, table: 'flora_request_processing', as: null }],
where: null,
groupby: null,
having: null,
Expand Down
Loading

0 comments on commit 2ff08c7

Please sign in to comment.