Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ozziest committed Dec 22, 2023
1 parent edf17ea commit c9fae9e
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 8 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ jobs:
- run: |
npm ci
npm run build
cd node-tester/cjs
npm install
node index.js
cd ../esm
npm install
node index.js
cd tests/consumers/cjs && npm install && node index.js
cd ../esm && npm install && node index.js
cd ../ts && npm install && npm run start
linting:
runs-on: ubuntu-latest
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions tests/consumers/ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { validate, setLocales } from "axe-api-validator";
import en from "axe-api-validator/dist/i18n/en.json";

const data = {
email: null,
};

const rules = {
email: "required|email|min:1|max:50",
};

const main = async () => {
setLocales(en);
const result = await validate(data, rules);
if (result.isValid) {
throw new Error("The email should be invalid!");
}

const { message } = result.errors.email[0];
if (message !== "The field field is required.") {
throw new Error(`Unaccepted message: ${message}`);
}

console.log("ESM module tests are succeed!");
};

main();
113 changes: 113 additions & 0 deletions tests/consumers/ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/consumers/ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "tester",
"version": "1.0.0",
"main": "index.ts",
"type": "module",
"scripts": {
"start": "tsc"
},
"dependencies": {
"axe-api-validator": "file:../../"
},
"devDependencies": {
"typescript": "^5.3.3"
}
}
17 changes: 17 additions & 0 deletions tests/consumers/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"allowSyntheticDefaultImports": true,
"declaration": true,
"resolveJsonModule": true
},
"include": ["index.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, describe, expect, test } from "vitest";
import { setOptions, validate } from "../src/index";
import { setOptions, validate } from "../index";
import { setLocales } from "../src/Locale";
import en from "../src/i18n/en.json";
import tr from "../src/i18n/tr.json";
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, "./docs/**"],
exclude: [...configDefaults.exclude, "./docs/**", "./tests/consumers"],
},
});

0 comments on commit c9fae9e

Please sign in to comment.