hydra
hydra copied to clipboard
Make hydra-cli tests pass on Windows
The following tests are failing when I run yarn test
:
-
Should generate migration
-
should render otm types
-
should render mto types
VERSION @dzlzv/hydra-cli/0.1.6 win32-x64 node-v12.20.2
yarn test
yarn run v1.22.0
$ nyc --extension .ts mocha --forbid-only "test/**/*.test.ts"
EnumRenderer
√ should render enum values (255ms)
ExplicitIdFieldRemoval
√ should remove id field from entities
FTSQueryRenderer
1) Should generate migration
√ Should add filter options to fts resolver
√ Should add filter options to fts service
ModelRenderer
√ should transform fields to camelCase (55ms)
√ should render ClassName
√ should include imports (51ms)
2) should render otm types
3) should render mto types
√ should add nullable option mto decorator
√ should renderer array types
√ should render enum types
√ should decorate field with the correct enum type
√ should import and export both enums
√ should export enum from a single entity
√ should extend interface type
√ should not include interface field
√ should render interface
√ should import unions
√ Should add transformer for BigInt fields
√ Should add required object definations for Pagination (64ms)
√ Should properly pluralize connection naming for camelCased names (125ms)
√ Should add querying a single entity query (46ms)
SchemaParser
√ should fail on non-existent file
√ should find a top-level entity
√ should throw an error on invalid schema
√ should throw on unknown directive
√ should throw on wrong location
√ should throw on wrong argument
√ should detect fields types and directives
√ should load file
√ should visit directives
VariantsRenderer
√ Should render union types
√ Should import enums
WarthogModel
√ Should lookup entities
√ Should lookup fields
√ Should add queries
√ Should add enums
√ Should add interfaces
√ Should should ignore interfaces without @entity
√ Should add interfaces to entities
√ Should lookup types
√ Should add variants and unions
√ Should throw on non-variant union
√ Should add a union field to an entity
WarthogModelBuild
√ should add multi-field multi-entity FTSQuery to the model (41ms)
√ should detect multiple queries
45 passing (1s)
3 failing
1) FTSQueryRenderer
Should generate migration:
AssertionError: expected 'import { MigrationInterface, QueryRunner } from "typeorm";\r\n\r\nexport class Test1Migration111111111 implements MigrationInterface {\r\n name = \'test1Migration111111111\'\r\n\r\n public async up(queryRunner: QueryRunner): Promise<void> {\r\n // TODO: escape \r\n await queryRunner.query(`\r\n ALTER TABLE post \r\n ADD COLUMN test1_tsv tsvector \r\n GENERATED ALWAYS AS ( \r\n setweight(to_tsvector(\'english\', coalesce("initial_body_text", \'\')), \'A\') || \r\n setweight(to_tsvector(\'english\', coalesce("title", \'\')), \'A\') \r\n ) \r\n STORED;\r\n `);\r\n await queryRunner.query(`\r\n ALTER TABLE
post \r\n ADD COLUMN test1_doc text \r\n GENERATED ALWAYS AS ( \r\n coalesce("initial_body_text", \'\') || \r\n coalesce("title", \'\') \r\n ) \r\n STORED;\r\n `);\r\n await queryRunner.query(`CREATE INDEX test1_post_idx ON post USING GIN (test1_tsv)`);\r\n await queryRunner.query(`CREATE INDEX post_id_idx ON post ((\'post\' || \'_\' || id))`);\r\n await queryRunner.query(`\r\n ALTER TABLE thread \r\n ADD COLUMN test1_tsv tsvector \r\n GENERATED ALWAYS AS ( \r\n setweight(to_tsvector(\'english\', coalesce("initial_body_text", \'\')), \'A\') || \r\n setweight(to_tsvector(\'english\', coalesce("title", \'\')), \'A\') \r\n ) \r\n STORED;\r\n `);\r\n await queryRunner.query(`\r\n
ALTER TABLE thread \r\n ADD COLUMN test1_doc text \r\n GENERATED ALWAYS AS ( \r\n
coalesce("initial_body_text", \'\') || \r\n coalesce("title", \'\') \r\n ) \r\n STORED;\r\n `);\r\n await queryRunner.query(`CREATE INDEX test1_thread_idx ON thread USING GIN (test1_tsv)`);\r\n
await queryRunner.query(`CREATE INDEX thread_id_idx ON thread ((\'thread\' || \'_\' || id))`);\r\n\r\n await queryRunner.query(`\r\n CREATE VIEW test1_view AS\r\n SELECT \r\n text \'post\' AS origin_table, \'post\' ||
\'_\' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document \r\n FROM\r\n post\r\n UNION ALL\r\n SELECT \r\n text \'thread\' AS origin_table, \'thread\' || \'_\' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document \r\n FROM\r\n thread\r\n `);\r\n\r\n }\r\n\r\n public async down(queryRunner: QueryRunner): Promise<void> {\r\n await queryRunner.query(`DROP VIEW test1_view`);\r\n await queryRunner.query(`DROP INDEX test1_post_idx`);\r\n await queryRunner.query(`DROP INDEX post_id_idx`);\r\n await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_tsv`);\r\n await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_doc`);\r\n await queryRunner.query(`DROP INDEX test1_thread_idx`);\r\n await queryRunner.query(`DROP INDEX thread_id_idx`);\r\n await queryRunner.query(`ALTER TABLE thread DROP COLUMN test1_tsv`);\r\n await queryRunner.query(`ALTER TABLE
thread DROP COLUMN test1_doc`);\r\n }\r\n\r\n\r\n}\r\n' to equal 'import { MigrationInterface, QueryRunner } from "typeorm";\n\nexport class Test1Migration111111111 implements MigrationInterface {\n name = \'test1Migration111111111\'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n // TODO: escape \n await queryRunner.query(`\n ALTER TABLE post \n ADD COLUMN test1_tsv tsvector \n GENERATED ALWAYS AS ( \n setweight(to_tsvector(\'english\', coalesce("initial_body_text", \'\')), \'A\') || \n setweight(to_tsvector(\'english\', coalesce("title", \'\')), \'A\') \n ) \n STORED;\n `);\n await queryRunner.query(`\n ALTER TABLE post \n ADD COLUMN test1_doc text \n GENERATED ALWAYS AS ( \n coalesce("initial_body_text", \'\') || \n coalesce("title", \'\') \n ) \n STORED;\n `);\n await queryRunner.query(`CREATE INDEX test1_post_idx ON post USING GIN (test1_tsv)`);\n await queryRunner.query(`CREATE INDEX post_id_idx ON post ((\'post\' || \'_\' || id))`);\n await queryRunner.query(`\n ALTER TABLE thread \n ADD COLUMN test1_tsv tsvector \n GENERATED ALWAYS AS ( \n setweight(to_tsvector(\'english\', coalesce("initial_body_text", \'\')), \'A\') || \n setweight(to_tsvector(\'english\', coalesce("title", \'\')), \'A\') \n ) \n STORED;\n `);\n await queryRunner.query(`\n ALTER TABLE thread \n
ADD COLUMN test1_doc text \n GENERATED ALWAYS AS ( \n coalesce("initial_body_text", \'\') || \n coalesce("title", \'\') \n ) \n STORED;\n `);\n await queryRunner.query(`CREATE INDEX test1_thread_idx ON thread USING GIN (test1_tsv)`);\n await queryRunner.query(`CREATE INDEX thread_id_idx ON
thread ((\'thread\' || \'_\' || id))`);\n\n await queryRunner.query(`\n CREATE VIEW test1_view AS\n SELECT \n text \'post\' AS origin_table, \'post\' || \'_\' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document \n FROM\n post\n UNION ALL\n SELECT \n text \'thread\' AS origin_table, \'thread\' || \'_\' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document \n FROM\n thread\n `);\n\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n await queryRunner.query(`DROP VIEW test1_view`);\n await queryRunner.query(`DROP INDEX test1_post_idx`);\n await queryRunner.query(`DROP INDEX post_id_idx`);\n await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_tsv`);\n await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_doc`);\n await queryRunner.query(`DROP INDEX test1_thread_idx`);\n await queryRunner.query(`DROP INDEX thread_id_idx`);\n await queryRunner.query(`ALTER TABLE thread DROP COLUMN test1_tsv`);\n await queryRunner.query(`ALTER TABLE thread DROP COLUMN test1_doc`);\n }\n\n\n}\n'
+ expected - actual
-import { MigrationInterface, QueryRunner } from "typeorm";
-
-export class Test1Migration111111111 implements MigrationInterface {
- name = 'test1Migration111111111'
-
- public async up(queryRunner: QueryRunner): Promise<void> {
- // TODO: escape
- await queryRunner.query(`
- ALTER TABLE post
- ADD COLUMN test1_tsv tsvector
- GENERATED ALWAYS AS (
- setweight(to_tsvector('english', coalesce("initial_body_text", '')), 'A') ||
- setweight(to_tsvector('english', coalesce("title", '')), 'A')
- )
- STORED;
- `);
- await queryRunner.query(`
- ALTER TABLE post
- ADD COLUMN test1_doc text
- GENERATED ALWAYS AS (
- coalesce("initial_body_text", '') ||
- coalesce("title", '')
- )
- STORED;
- `);
- await queryRunner.query(`CREATE INDEX test1_post_idx ON post USING GIN (test1_tsv)`);
- await queryRunner.query(`CREATE INDEX post_id_idx ON post (('post' || '_' || id))`);
- await queryRunner.query(`
- ALTER TABLE thread
- ADD COLUMN test1_tsv tsvector
- GENERATED ALWAYS AS (
- setweight(to_tsvector('english', coalesce("initial_body_text", '')), 'A') ||
- setweight(to_tsvector('english', coalesce("title", '')), 'A')
- )
- STORED;
- `);
- await queryRunner.query(`
- ALTER TABLE thread
- ADD COLUMN test1_doc text
- GENERATED ALWAYS AS (
- coalesce("initial_body_text", '') ||
- coalesce("title", '')
- )
- STORED;
- `);
- await queryRunner.query(`CREATE INDEX test1_thread_idx ON thread USING GIN (test1_tsv)`);
- await queryRunner.query(`CREATE INDEX thread_id_idx ON thread (('thread' || '_' || id))`);
-
- await queryRunner.query(`
- CREATE VIEW test1_view AS
- SELECT
- text 'post' AS origin_table, 'post' || '_' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document
- FROM
- post
- UNION ALL
- SELECT
- text 'thread' AS origin_table, 'thread' || '_' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document
- FROM
- thread
- `);
-
- }
-
- public async down(queryRunner: QueryRunner): Promise<void> {
- await queryRunner.query(`DROP VIEW test1_view`);
- await queryRunner.query(`DROP INDEX test1_post_idx`);
- await queryRunner.query(`DROP INDEX post_id_idx`);
- await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_tsv`);
- await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_doc`);
- await queryRunner.query(`DROP INDEX test1_thread_idx`);
- await queryRunner.query(`DROP INDEX thread_id_idx`);
- await queryRunner.query(`ALTER TABLE thread DROP COLUMN test1_tsv`);
- await queryRunner.query(`ALTER TABLE thread DROP COLUMN test1_doc`);
- }
-
-
-}
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class Test1Migration111111111 implements MigrationInterface {
+ name = 'test1Migration111111111'
+
+ public async up(queryRunner: QueryRunner): Promise<void> {
+ // TODO: escape
+ await queryRunner.query(`
+ ALTER TABLE post
+ ADD COLUMN test1_tsv tsvector
+ GENERATED ALWAYS AS (
+ setweight(to_tsvector('english', coalesce("initial_body_text", '')), 'A') ||
+ setweight(to_tsvector('english', coalesce("title", '')), 'A')
+ )
+ STORED;
+ `);
+ await queryRunner.query(`
+ ALTER TABLE post
+ ADD COLUMN test1_doc text
+ GENERATED ALWAYS AS (
+ coalesce("initial_body_text", '') ||
+ coalesce("title", '')
+ )
+ STORED;
+ `);
+ await queryRunner.query(`CREATE INDEX test1_post_idx ON post USING GIN (test1_tsv)`);
+ await queryRunner.query(`CREATE INDEX post_id_idx ON post (('post' || '_' || id))`);
+ await queryRunner.query(`
+ ALTER TABLE thread
+ ADD COLUMN test1_tsv tsvector
+ GENERATED ALWAYS AS (
+ setweight(to_tsvector('english', coalesce("initial_body_text", '')), 'A') ||
+ setweight(to_tsvector('english', coalesce("title", '')), 'A')
+ )
+ STORED;
+ `);
+ await queryRunner.query(`
+ ALTER TABLE thread
+ ADD COLUMN test1_doc text
+ GENERATED ALWAYS AS (
+ coalesce("initial_body_text", '') ||
+ coalesce("title", '')
+ )
+ STORED;
+ `);
+ await queryRunner.query(`CREATE INDEX test1_thread_idx ON thread USING GIN (test1_tsv)`);
+ await queryRunner.query(`CREATE INDEX thread_id_idx ON thread (('thread' || '_' || id))`);
+
+ await queryRunner.query(`
+ CREATE VIEW test1_view AS
+ SELECT
+ text 'post' AS origin_table, 'post' || '_' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document
+ FROM
+ post
+ UNION ALL
+ SELECT
+ text 'thread' AS origin_table, 'thread' || '_' || id AS unique_id, id, test1_tsv AS tsv, test1_doc AS document
+ FROM
+ thread
+ `);
+
+ }
+
+ public async down(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(`DROP VIEW test1_view`);
+ await queryRunner.query(`DROP INDEX test1_post_idx`);
+ await queryRunner.query(`DROP INDEX post_id_idx`);
+ await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_tsv`);
+ await queryRunner.query(`ALTER TABLE post DROP COLUMN test1_doc`);
+ await queryRunner.query(`DROP INDEX test1_thread_idx`);
+ await queryRunner.query(`DROP INDEX thread_id_idx`);
+ await queryRunner.query(`ALTER TABLE thread DROP COLUMN test1_tsv`);
+ await queryRunner.query(`ALTER TABLE thread DROP COLUMN test1_doc`);
+ }
+
+
+}
at Proxy.<anonymous> (C:\Users\jamie\Desktop\hydra\node_modules\mocha-chai-snapshot\src\index.js:85:25)
at Proxy.methodWrapper (C:\Users\jamie\Desktop\hydra\node_modules\chai\lib\chai\utils\addMethod.js:57:25)
at Context.<anonymous> (test\helpers\FTSQueryRenderer.test.ts:41:38)
at processImmediate (internal/timers.js:461:21)
2) ModelRenderer
should render otm types:
AssertionError: Should render imports: expected 'import { BaseModel, Model, OneToMany, StringField } from \'warthog\';\n\nimport { Post } from \'..postpost.model\';\n\n@Model({ api: {} })\nexport class Author extends BaseModel {\n @OneToMany(() => Post, (param: Post) => param.author)\n posts?: Post[];\n\n constructor(init?: Partial<Author>) {\n super();\n Object.assign(this, init);\n }\n}\n' to include 'import { Post } from \'../post/post.model'
at Context.<anonymous> (test\helpers\ModelRenderer.test.ts:134:25)
at processImmediate (internal/timers.js:461:21)
3) ModelRenderer
should render mto types:
AssertionError: Should render imports: expected 'import { BaseModel, Model, ManyToOne, StringField } from \'warthog\';\n\nimport { Author } from \'..authorauthor.model\';\n\n@Model({ api: {} })\nexport class Post extends BaseModel {\n @StringField({\n nullable: true,\n })\n title?: string;\n\n @ManyToOne(() => Author, (param: Author) => param.postauthor, { skipGraphQLField: true })\n author!: Author;\n\n constructor(init?: Partial<Post>) {\n super();\n Object.assign(this, init);\n }\n}\n' to include 'import { Author } from \'../author/author.model'
at Context.<anonymous> (test\helpers\ModelRenderer.test.ts:167:25)
at processImmediate (internal/timers.js:461:21)
---------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---------------------------|----------|----------|----------|----------|-------------------|
All files | 77.97 | 64.04 | 83.67 | 78.13 | |
generate | 73.03 | 58.71 | 73.68 | 73.18 | |
AbstractRenderer.ts | 100 | 100 | 100 | 100 | |
ConfigProvider.ts | 33.33 | 100 | 0 | 33.33 |... 23,24,28,34,38 |
EnumContextProvider.ts | 100 | 100 | 100 | 100 | |
EnumRenderer.ts | 100 | 100 | 100 | 100 | |
FTSQueryRenderer.ts | 97.37 | 57.14 | 100 | 97.37 | 62 |
ModelRenderer.ts | 98.55 | 92 | 100 | 98.41 | 118 |
RelationshipGenerator.ts | 59.57 | 48.1 | 76.47 | 61.9 |... 53,260,264,265 |
SourcesGenerator.ts | 22.08 | 0 | 0 | 22.08 |... 79,183,185,186 |
VariantsRenderer.ts | 100 | 100 | 100 | 100 | |
enum-context.ts | 91.67 | 100 | 80 | 91.67 | 28 |
field-context.ts | 89.8 | 72.22 | 91.67 | 89.58 |... 46,167,168,170 |
union-context.ts | 92.31 | 100 | 80 | 91.67 | 27 |
utils.ts | 85.71 | 75 | 66.67 | 84.85 | 10,11,12,63,67 |
model | 87.12 | 79.03 | 96.49 | 87.92 | |
Field.ts | 100 | 93.33 | 100 | 100 | 55 |
Relation.ts | 100 | 100 | 100 | 100 | |
ScalarTypes.ts | 100 | 100 | 100 | 100 | |
WarthogModel.ts | 90.99 | 78.05 | 100 | 92.86 |... ,62,63,190,255 |
index.ts | 100 | 100 | 100 | 100 | |
relations.ts | 47.37 | 0 | 50 | 47.37 |... 49,55,64,65,67 |
validate.ts | 66.67 | 50 | 100 | 66.67 | 5 |
parse | 89.13 | 73.95 | 98.51 | 89.14 | |
DerivedFromDirective.ts | 81.82 | 72.73 | 100 | 80 | 15,24,40,43 |
FTSDirective.ts | 78.38 | 64.29 | 100 | 78.38 |... 41,44,47,75,85 |
SchemaDirective.ts | 100 | 100 | 100 | 100 | |
SchemaParser.ts | 89.29 | 86.96 | 95.65 | 90.57 |... 03,104,105,157 |
WarthogModelBuilder.ts | 93.58 | 73.91 | 100 | 93.33 |... 30,135,144,172 |
constant.ts | 100 | 100 | 100 | 100 | |
utils | 28.95 | 0 | 0 | 29.73 | |
utils.ts | 28.95 | 0 | 0 | 29.73 |... 81,82,85,94,95 |
---------------------------|----------|----------|----------|----------|-------------------|
error Command failed with exit code 3.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I tested it on windows, getting the same error, it is a platform-specific issue.
Ok, thanks for letting me know
After installing Ubuntu on my laptop I can also confirm that it was a Windows only issues
The reason is the formatting of the text fixtures uses the Unix-based line endings, so on Windows the expected outcome does not match the actual result. We should make it platform-independent by e.g. stripping whitespace characters from the fixtures before comparing with the output.