Skip to content

Commit

Permalink
test(next-drupal): reorganize Jest tests
Browse files Browse the repository at this point in the history
Fixes #608
  • Loading branch information
JohnAlbin committed Feb 21, 2024
1 parent dbb6e91 commit 807a1d6
Show file tree
Hide file tree
Showing 30 changed files with 9,383 additions and 6,673 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.diff,*.patch}]
trim_trailing_whitespace = false
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
"faker": "^6.6.6",
"husky": "^8.0.3",
"isomorphic-fetch": "^3.0.0",
"jest": "^27.5.1",
"jest": "^29.7.0",
"lerna": "^8.0.1",
"lint-staged": "^15.0.2",
"prettier": "^3.0.3",
"start-server-and-test": "^1.15.5",
"ts-jest": "^27.1.5",
"ts-node": "^10.9.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsup": "^7.3.0",
"turbo": "^1.10.15",
"typescript": "^5.2.2",
Expand Down
16 changes: 10 additions & 6 deletions packages/next-drupal-query/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest/presets/js-with-ts",
testEnvironment: "node",
setupFiles: ["dotenv/config"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testMatch: ["**/tests/**/*.test.{ts,tsx}"],
globals: {
"ts-jest": {
isolatedModules: true,
},
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
isolatedModules: true,
},
],
},
testLocationInResults: true,
coverageProvider: "v8",
collectCoverage: true,
collectCoverageFrom: ["./src/**"],
coverageReporters: ["lcov", "text", "text-summary"],
coverageThreshold: {
global: {
statements: 85.11,
branches: 58,
branches: 67.56,
functions: 70,
lines: 85.11,
},
Expand Down
42 changes: 21 additions & 21 deletions packages/next-drupal-query/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`formatData it formats data 1`] = `
Object {
{
"name": "First Last",
}
`;

exports[`getData it accepts data options 1`] = `
Object {
{
"author": "shadcn",
"id": "ID",
"title": "Title of Article",
Expand All @@ -16,14 +16,14 @@ Object {
`;

exports[`getData it accepts placeholder options 1`] = `
Object {
{
"email": "name@example.com",
"name": "shadcn",
}
`;

exports[`getData it returns data for a query 1`] = `
Object {
{
"author": "shadcn",
"id": "id",
"title": "Title of Article",
Expand All @@ -32,52 +32,52 @@ Object {
`;

exports[`getData it returns data when both data and placeholder is defined 1`] = `
Object {
{
"email": "foo@example.com",
}
`;

exports[`getData it returns formatted data if a formatter is defined 1`] = `
Object {
{
"email": "foo@example.com",
"name": "First Last",
}
`;

exports[`getData it returns placeholder data if a query does not define data 1`] = `
Object {
{
"name": "shadcn",
}
`;

exports[`getParams it accepts params options 1`] = `
Object {
"fields": Object {
{
"fields": {
"resource": "foo,bar",
},
"filter": Object {},
"include": Array [],
"sort": Array [],
"filter": {},
"include": [],
"sort": [],
}
`;

exports[`getParams it allows params to be nested 1`] = `
Object {
"fields": Object {},
"filter": Object {},
{
"fields": {},
"filter": {},
"include": "field_image,uid",
"page": Object {
"page": {
"limit": 10,
},
"sort": Array [],
"sort": [],
}
`;

exports[`getParams it returns params for a query 1`] = `
Object {
"fields": Object {},
"filter": Object {},
{
"fields": {},
"filter": {},
"include": "field_image,uid",
"sort": Array [],
"sort": [],
}
`;
22 changes: 13 additions & 9 deletions packages/next-drupal/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
setupFiles: ["dotenv/config"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testMatch: ["**/tests/**/*.test.{ts,tsx}"],
globals: {
"ts-jest": {
isolatedModules: true,
},
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
isolatedModules: true,
},
],
},
testLocationInResults: true,
coverageProvider: "v8",
collectCoverage: true,
collectCoverageFrom: ["./src/**"],
Expand All @@ -22,10 +26,10 @@ module.exports = {
coverageReporters: ["lcov", "text", "text-summary"],
coverageThreshold: {
global: {
statements: 82.07,
branches: 86.9,
functions: 80.76,
lines: 82.07,
statements: 100,
branches: 100,
functions: 100,
lines: 100,
},
},
}
Loading

0 comments on commit 807a1d6

Please sign in to comment.