Skip to content

Commit

Permalink
upgrade vitest from 0.x to 1.x (#278)
Browse files Browse the repository at this point in the history
* upgrade vitest to 1.0

* update vitest to 1.0

* fix snapshots

* update test workflow to use node 18 exclusively

* update to latest vitest to fix snapshot issue

* fix tests

* fix more tests

* add comments

* test: simplify type aliases for tests

* add vitest config to enable typechecking

* add vitest config file

* add viteconfig to build exclusion

* test: do not build test files

* Bumping sanity to 3.15.0

* put test back the way it was previously

---------

Co-authored-by: Sawyer Burnett <sawyer.burnett@formidable.com>
Co-authored-by: scottrippey <scott.william.rippey@gmail.com>
  • Loading branch information
3 people committed Mar 22, 2024
1 parent 3fa5b46 commit 38f3f23
Show file tree
Hide file tree
Showing 26 changed files with 1,125 additions and 2,138 deletions.
8 changes: 8 additions & 0 deletions .changeset/thirty-glasses-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"playground-example": patch
"groqd-playground": patch
"groq-builder": patch
"groqd": patch
---

bump Sanity to 3.15.0. bump vitest to 1.3.1
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 examples/playground-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"sanity": "^3.14.0",
"sanity": "^3.15.0",
"styled-components": "^5.2.0",
"groqd-playground": "*"
},
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.3.1"
},
"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"] {
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:
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"]`
);
});
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
Loading

0 comments on commit 38f3f23

Please sign in to comment.