From 175cc2edc02a2bb58db4557812c00b657f708ca6 Mon Sep 17 00:00:00 2001 From: doug-martin Date: Mon, 10 Aug 2020 00:06:19 -0500 Subject: [PATCH] fix(e2e): Making tests deterministic --- examples/helpers/db-test.helpers.ts | 4 ++-- examples/helpers/sequelize.helpers.ts | 2 ++ examples/no-paging/e2e/todo-item.resolver.spec.ts | 2 +- examples/offset-paging/e2e/tag.resolver.spec.ts | 8 ++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/helpers/db-test.helpers.ts b/examples/helpers/db-test.helpers.ts index 5cd8bdf25..a1468742a 100644 --- a/examples/helpers/db-test.helpers.ts +++ b/examples/helpers/db-test.helpers.ts @@ -1,9 +1,9 @@ export const dbType = process.env.NESTJS_QUERY_DB_TYPE ?? 'postgres'; export const truncateSql = (table: string): string[] => { if (dbType === 'mysql') { - return [`DELETE FROM ${table}`, `ALTER TABLE ${table} AUTO_INCREMENT = 1`]; + return [`DELETE FROM \`${table}\``, `ALTER TABLE \`${table}\` AUTO_INCREMENT = 1`]; } - return [`TRUNCATE ${table} RESTART IDENTITY CASCADE`]; + return [`TRUNCATE "${table}" RESTART IDENTITY CASCADE`]; }; interface QueryExecutor { diff --git a/examples/helpers/sequelize.helpers.ts b/examples/helpers/sequelize.helpers.ts index 1bc9911b2..dd48a4b7d 100644 --- a/examples/helpers/sequelize.helpers.ts +++ b/examples/helpers/sequelize.helpers.ts @@ -14,6 +14,7 @@ export const sequelizeMysqlOptions = ( database, autoLoadModels: true, synchronize: true, + logging: false, ...overrides, }; }; @@ -31,6 +32,7 @@ export const sequelizePostgresOptions = ( database, autoLoadModels: true, synchronize: true, + logging: false, ...overrides, }; }; diff --git a/examples/no-paging/e2e/todo-item.resolver.spec.ts b/examples/no-paging/e2e/todo-item.resolver.spec.ts index ac05e3686..1bdb2f021 100644 --- a/examples/no-paging/e2e/todo-item.resolver.spec.ts +++ b/examples/no-paging/e2e/todo-item.resolver.spec.ts @@ -84,7 +84,7 @@ describe('TodoItemResolver (noPaging - e2e)', () => { variables: {}, query: `{ todoItem(id: 1) { - subTasks { + subTasks(sorting: { field: id, direction: ASC }) { ${subTaskFields} } } diff --git a/examples/offset-paging/e2e/tag.resolver.spec.ts b/examples/offset-paging/e2e/tag.resolver.spec.ts index 4de0f498c..9d7022952 100644 --- a/examples/offset-paging/e2e/tag.resolver.spec.ts +++ b/examples/offset-paging/e2e/tag.resolver.spec.ts @@ -582,11 +582,11 @@ describe('TagResolver (limitOffset - e2e)', () => { const { id, todoItems }: { id: string; todoItems: TodoItemDTO[] } = body.data.addTodoItemsToTag; expect(id).toBe('1'); expect(todoItems).toHaveLength(5); - expect(todoItems.map((e) => e.title)).toEqual([ - 'Create Nest App', + expect(todoItems.map((e) => e.title).sort()).toEqual([ + 'Add Todo Item Resolver', 'Create Entity', 'Create Entity Service', - 'Add Todo Item Resolver', + 'Create Nest App', 'How to create item With Sub Tasks', ]); }); @@ -619,7 +619,7 @@ describe('TagResolver (limitOffset - e2e)', () => { const { id, todoItems }: { id: string; todoItems: TodoItemDTO[] } = body.data.removeTodoItemsFromTag; expect(id).toBe('1'); expect(todoItems).toHaveLength(2); - expect(todoItems.map((e) => e.title)).toEqual(['Create Nest App', 'Create Entity']); + expect(todoItems.map((e) => e.title).sort()).toEqual(['Create Entity', 'Create Nest App']); }); }); });