Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade vitest from 0.x to 1.x #278

Merged
merged 19 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pnpm run build

## Run tests

Test are written using [vitest](https://www.npmjs.com/package/vitest). To run tests, node 18 or later must be used.

```sh
pnpm run test

Expand Down
2 changes: 1 addition & 1 deletion packages/groq-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"groq-js": "^1.1.9",
"rimraf": "^5.0.5",
"typescript": "^5.0.4",
"vitest": "^0.28.5"
"vitest": "^1.0.0"
},
"engines": {
"node": ">= 14"
Expand Down
18 changes: 9 additions & 9 deletions packages/groq-builder/src/commands/conditional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ describe("conditional", () => {
it("the query should look correct", () => {
expect(qAll.query).toMatchInlineSnapshot(
`
"*[_type == \\"variant\\"] {
"*[_type == "variant"] {
Burnett2k marked this conversation as resolved.
Show resolved Hide resolved
name,
price == msrp => {
\\"onSale\\": false
"onSale": false
},
price < msrp => {
\\"onSale\\": true,
"onSale": true,
price,
msrp
}
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("conditional", () => {
});
it("the query will also be missing the first conditionals", () => {
expect(qIncorrect.query).toMatchInlineSnapshot(`
"*[_type == \\"variant\\"] {
"*[_type == "variant"] {
name,
second == condition => {
price
Expand Down Expand Up @@ -178,21 +178,21 @@ describe("conditional", () => {

it("the query should be compiled correctly", () => {
expect(qMultipleConditions.query).toMatchInlineSnapshot(`
"*[_type == \\"variant\\"] {
"*[_type == "variant"] {
name,
price == msrp => {
\\"onSale\\": false
"onSale": false
},
price < msrp => {
\\"onSale\\": true,
"onSale": true,
price,
msrp
},
another == condition1 => {
\\"foo\\": \\"FOO\\"
"foo": "FOO"
},
another == condition2 => {
\\"bar\\": \\"BAR\\"
"bar": "BAR"
}
}"
`);
Expand Down
16 changes: 8 additions & 8 deletions packages/groq-builder/src/commands/conditionalByType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ describe("conditionalByType", () => {
expect(qMultiple.query).toMatchInlineSnapshot(`
"* {
_type,
_type == \\"variant\\" => {
_type == "variant" => {
price
},
_type == \\"product\\" => {
\\"slug\\": slug.current
_type == "product" => {
"slug": slug.current
},
_type == \\"category\\" => {
_type == "category" => {
description
},
_type == \\"style\\" => {
_type == "style" => {
name
}
}"
Expand Down Expand Up @@ -169,12 +169,12 @@ describe("conditionalByType", () => {
expect(qAll.query).toMatchInlineSnapshot(`
"* {
_type,
_type == \\"product\\" => {
_type == "product" => {
_type,
name,
\\"slug\\": slug.current
"slug": slug.current
},
_type == \\"variant\\" => {
_type == "variant" => {
name,
price
}
Expand Down
4 changes: 2 additions & 2 deletions packages/groq-builder/src/commands/deref.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("deref", () => {
InferResultType<typeof qCategory>
>().toEqualTypeOf<SanitySchema.Category | null>();
expect(qCategory.query).toMatchInlineSnapshot(
'"*[_type == \\"product\\"][0].categories[][0]->"'
`"*[_type == "product"][0].categories[][0]->"`
);
});

Expand All @@ -30,7 +30,7 @@ describe("deref", () => {
InferResultType<typeof qVariants>
>().toEqualTypeOf<Array<SanitySchema.Variant> | null>();
expect(qVariants.query).toMatchInlineSnapshot(
'"*[_type == \\"product\\"][0].variants[]->"'
`"*[_type == "product"][0].variants[]->"`
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/groq-builder/src/commands/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("filter", () => {
Array<SanitySchema.Variant>
>();
expect(qAnything.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"][ANYTHING]"'
`"*[_type == "variant"][ANYTHING]"`
);
});

Expand Down
16 changes: 8 additions & 8 deletions packages/groq-builder/src/commands/fragment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ describe("fragment", () => {

expect(qVariants.query).toMatchInlineSnapshot(
`
"*[_type == \\"variant\\"] {
"*[_type == "variant"] {
name,
price,
\\"slug\\": slug.current
"slug": slug.current
}"
`
);
Expand All @@ -77,10 +77,10 @@ describe("fragment", () => {

expect(qVariantsPlus.query).toMatchInlineSnapshot(
`
"*[_type == \\"variant\\"] {
"*[_type == "variant"] {
name,
price,
\\"slug\\": slug.current,
"slug": slug.current,
msrp
}"
`
Expand Down Expand Up @@ -181,14 +181,14 @@ describe("fragment", () => {

it("the query is compiled correctly", () => {
expect(qConditional.query).toMatchInlineSnapshot(`
"*[_type == \\"variant\\"] {
\\"slug\\": slug.current,
"*[_type == "variant"] {
"slug": slug.current,
name,
price == msrp => {
\\"onSale\\": false
"onSale": false
},
price < msrp => {
\\"onSale\\": true,
"onSale": true,
price,
msrp
}
Expand Down
48 changes: 24 additions & 24 deletions packages/groq-builder/src/commands/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("project (object projections)", () => {

it("should have the correct query", () => {
expect(qRoot.query).toMatchInlineSnapshot(
'" { \\"productNames\\": *[_type == \\"product\\"].name, \\"categoryNames\\": *[_type == \\"category\\"].name }"'
`" { "productNames": *[_type == "product"].name, "categoryNames": *[_type == "category"].name }"`
);
});

Expand Down Expand Up @@ -87,7 +87,7 @@ describe("project (object projections)", () => {
});
it("query should be typed correctly", () => {
expect(qName.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { name }"'
`"*[_type == "variant"] { name }"`
);

expectTypeOf<InferResultType<typeof qName>>().toEqualTypeOf<
Expand Down Expand Up @@ -130,7 +130,7 @@ describe("project (object projections)", () => {
});
it("query should be typed correctly", () => {
expect(qMultipleFields.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { id, name, price, msrp }"'
`"*[_type == "variant"] { id, name, price, msrp }"`
);

expectTypeOf<InferResultType<typeof qMultipleFields>>().toEqualTypeOf<
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("project (object projections)", () => {
});
it("query should be typed correctly", () => {
expect(qValidation.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { name, price }"'
`"*[_type == "variant"] { name, price }"`
);

expectTypeOf<InferResultType<typeof qValidation>>().toEqualTypeOf<
Expand Down Expand Up @@ -285,7 +285,7 @@ describe("project (object projections)", () => {

it("query should be correct", () => {
expect(qNakedProjections.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { \\"NAME\\": name, \\"SLUG\\": slug.current, msrp }"'
`"*[_type == "variant"] { "NAME": name, "SLUG": slug.current, msrp }"`
);
});

Expand Down Expand Up @@ -318,7 +318,7 @@ describe("project (object projections)", () => {

it("query should be correct", () => {
expect(qNakedProjections.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { \\"NAME\\": name, \\"SLUG\\": slug.current, msrp }"'
`"*[_type == "variant"] { "NAME": name, "SLUG": slug.current, msrp }"`
);
});

Expand All @@ -340,7 +340,7 @@ describe("project (object projections)", () => {

it("query should be correct", () => {
expect(qComplex.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { \\"NAME\\": name }"'
`"*[_type == "variant"] { "NAME": name }"`
);
});

Expand Down Expand Up @@ -385,7 +385,7 @@ describe("project (object projections)", () => {

it("query should be correct", () => {
expect(qComplex.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { name, \\"slug\\": slug.current, \\"images\\": images[].name }"'
`"*[_type == "variant"] { name, "slug": slug.current, "images": images[].name }"`
);
});

Expand Down Expand Up @@ -452,7 +452,7 @@ describe("project (object projections)", () => {

it("query should be correct", () => {
expect(qNested.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { name, \\"images\\": images[] { name, description } }"'
`"*[_type == "variant"] { name, "images": images[] { name, description } }"`
);
});

Expand Down Expand Up @@ -510,8 +510,8 @@ describe("project (object projections)", () => {
await expect(() =>
executeBuilder(qNested, { datalake: dataWithInvalidData })
).rejects.toThrowErrorMatchingInlineSnapshot(`
"1 Parsing Error:
result[0].images[0].description: Expected string, received number"
[ValidationErrors: 1 Parsing Error:
result[0].images[0].description: Expected string, received number]
`);
});
});
Expand All @@ -526,7 +526,7 @@ describe("project (object projections)", () => {

it("query should be correct", () => {
expect(qComplex.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { name, \\"slug\\": slug.current, price, \\"IMAGES\\": images[].name }"'
`"*[_type == "variant"] { name, "slug": slug.current, price, "IMAGES": images[].name }"`
);
});

Expand Down Expand Up @@ -603,7 +603,7 @@ describe("project (object projections)", () => {
});
it("the query shouldn't be affected", () => {
expect(qParser.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { name, msrp, price }"'
`"*[_type == "variant"] { name, msrp, price }"`
);
});
it("should execute correctly", async () => {
Expand Down Expand Up @@ -650,8 +650,8 @@ describe("project (object projections)", () => {

await expect(() => executeBuilder(qParser, { datalake: invalidData }))
.rejects.toThrowErrorMatchingInlineSnapshot(`
"1 Parsing Error:
result[5].price: Expected number, received string"
[ValidationErrors: 1 Parsing Error:
Burnett2k marked this conversation as resolved.
Show resolved Hide resolved
result[5].price: Expected number, received string]
`);
});
});
Expand All @@ -669,7 +669,7 @@ describe("project (object projections)", () => {
price: true,
})
).toThrowErrorMatchingInlineSnapshot(
'"[groq-builder] Because \'validationRequired\' is enabled, every field must have validation (like `q.string()`), but the following fields are missing it: \\"price\\""'
`[TypeError: [groq-builder] Because 'validationRequired' is enabled, every field must have validation (like \`q.string()\`), but the following fields are missing it: "price"]`
Burnett2k marked this conversation as resolved.
Show resolved Hide resolved
);
});
it("should throw if a projection uses a naked projection", () => {
Expand All @@ -678,7 +678,7 @@ describe("project (object projections)", () => {
price: "price",
})
).toThrowErrorMatchingInlineSnapshot(
'"[groq-builder] Because \'validationRequired\' is enabled, every field must have validation (like `q.string()`), but the following fields are missing it: \\"price\\""'
`[TypeError: [groq-builder] Because 'validationRequired' is enabled, every field must have validation (like \`q.string()\`), but the following fields are missing it: "price"]`
);
});
it("should throw if a nested projection is missing a parser", () => {
Expand All @@ -687,7 +687,7 @@ describe("project (object projections)", () => {
nested: qV.field("price"),
}))
).toThrowErrorMatchingInlineSnapshot(
'"[groq-builder] Because \'validationRequired\' is enabled, every field must have validation (like `q.string()`), but the following fields are missing it: \\"nested\\""'
`[TypeError: [groq-builder] Because 'validationRequired' is enabled, every field must have validation (like \`q.string()\`), but the following fields are missing it: "nested"]`
);
});
it("should throw when using ellipsis operator ...", () => {
Expand All @@ -696,7 +696,7 @@ describe("project (object projections)", () => {
"...": true,
})
).toThrowErrorMatchingInlineSnapshot(
'"[groq-builder] Because \'validationRequired\' is enabled, every field must have validation (like `q.string()`), but the following fields are missing it: \\"...\\""'
`[TypeError: [groq-builder] Because 'validationRequired' is enabled, every field must have validation (like \`q.string()\`), but the following fields are missing it: "..."]`
);
});
it("should work just fine when validation is provided", () => {
Expand All @@ -707,11 +707,11 @@ describe("project (object projections)", () => {
price4: qV.field("price").validate(q.number()),
}));
expect(qNormal.query).toMatchInlineSnapshot(`
"*[_type == \\"variant\\"][0] {
"*[_type == "variant"][0] {
price,
\\"price2\\": price,
\\"price3\\": price,
\\"price4\\": price
"price2": price,
"price3": price,
"price4": price
}"
`);
expectTypeOf<InferResultType<typeof qNormal>>().toEqualTypeOf<{
Expand All @@ -730,7 +730,7 @@ describe("project (object projections)", () => {
}));
it("query should be correct", () => {
expect(qEllipsis.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"] { ..., \\"OTHER\\": name }"'
`"*[_type == "variant"] { ..., "OTHER": name }"`
);
});

Expand Down
10 changes: 4 additions & 6 deletions packages/groq-builder/src/commands/projectField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ describe("field (naked projections)", () => {
Array<number>
>();
expect(qPrices.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"].price"'
`"*[_type == "variant"].price"`
);
});
it("can project a string", () => {
expectTypeOf<InferResultType<typeof qNames>>().toEqualTypeOf<
Array<string>
>();
expect(qNames.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"].name"'
);
expect(qNames.query).toMatchInlineSnapshot(`"*[_type == "variant"].name"`);
});
it("can project arrays with []", () => {
type ResultType = InferResultType<typeof qImages>;
Expand Down Expand Up @@ -98,7 +96,7 @@ describe("field (naked projections)", () => {
Array<string>
>();
expect(qSlugs.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"].slug.current"'
`"*[_type == "variant"].slug.current"`
);
});

Expand All @@ -121,7 +119,7 @@ describe("field (naked projections)", () => {
});
it("should result in the right query", () => {
expect(qPrice.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"][0].price"'
`"*[_type == "variant"][0].price"`
);
});
it("should execute correctly", async () => {
Expand Down
Loading
Loading