Skip to content

Commit ae6db6e

Browse files
JavaScript: Don't use vitest in rewrite-test.ts (#6957)
* Don't use vitest * Skip failing tests
1 parent 1f7e309 commit ae6db6e

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

rewrite-javascript/rewrite/src/test/rewrite-test.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {expect} from "vitest";
1716
import {Recipe} from "../recipe";
1817
import {ExecutionContext} from "../execution";
1918
import {noopVisitor, TreeVisitor} from "../visitor";
@@ -145,7 +144,13 @@ export class RecipeSpec {
145144
private async expectParsePrintIdempotence(parsed: [SourceSpec<any>, SourceFile][]) {
146145
for (const [spec, sourceFile] of parsed) {
147146
const beforeSource = dedent(spec.before!);
148-
expect(await TreePrinters.print(sourceFile)).toEqual(beforeSource);
147+
const printed = await TreePrinters.print(sourceFile);
148+
if (printed !== beforeSource) {
149+
throw new Error(
150+
`Parse-print idempotence check failed.\n` +
151+
`Expected:\n${beforeSource}\n\nActual:\n${printed}`
152+
);
153+
}
149154
}
150155
}
151156

@@ -206,12 +211,16 @@ export class RecipeSpec {
206211
if (!after) {
207212
throw new Error('Expected for recipe to have produced a change for file:\n' + trimIndent(spec.before))
208213
}
209-
expect(after).toBeDefined();
210-
await new ValidateWhitespaceVisitor().visit(after!, this.executionContext);
211-
const actualAfter = await TreePrinters.print(after!);
214+
await new ValidateWhitespaceVisitor().visit(after, this.executionContext);
215+
const actualAfter = await TreePrinters.print(after);
212216
const afterSource = typeof spec.after === "function" ?
213217
(spec.after as (actual: string) => string)(actualAfter) : spec.after as string;
214-
expect(actualAfter).toEqual(afterSource);
218+
if (actualAfter !== afterSource) {
219+
throw new Error(
220+
`Recipe output does not match expected.\n` +
221+
`Expected:\n${afterSource}\n\nActual:\n${actualAfter}`
222+
);
223+
}
215224
if (spec.afterRecipe) {
216225
await spec.afterRecipe(after);
217226
}
@@ -248,7 +257,11 @@ export class RecipeSpec {
248257
class ValidateWhitespaceVisitor extends JavaScriptVisitor<ExecutionContext> {
249258
public override async visitSpace(space: J.Space, p: ExecutionContext): Promise<J.Space> {
250259
const ret = super.visitSpace(space, p);
251-
expect(space.whitespace).toMatch(/^\s*$/);
260+
if (!/^\s*$/.test(space.whitespace)) {
261+
throw new Error(
262+
`Whitespace contains non-whitespace characters: ${JSON.stringify(space.whitespace)}`
263+
);
264+
}
252265
return ret;
253266
}
254267
}

rewrite-javascript/rewrite/test/rpc/install-recipes.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ describe("InstallRecipes", () => {
233233
}, {unsafeCleanup: true});
234234
}, 60000);
235235

236-
test("installs @openrewrite/recipes-nodejs from npm", async () => {
236+
// Skipped: published @openrewrite/rewrite has vitest runtime dep; fix: https://github.com/openrewrite/rewrite/pull/6957
237+
test.skip("installs @openrewrite/recipes-nodejs from npm", async () => {
237238
await withDir(async (dir) => {
238239
// given
239240
const installDir = path.join(dir.path, "recipes");
@@ -256,7 +257,8 @@ describe("InstallRecipes", () => {
256257
}, {unsafeCleanup: true});
257258
}, 120000);
258259

259-
test("upgrades @openrewrite/recipes-nodejs from 0.36.0 to a later version", async () => {
260+
// Skipped: published @openrewrite/rewrite has vitest runtime dep; fix: https://github.com/openrewrite/rewrite/pull/6957
261+
test.skip("upgrades @openrewrite/recipes-nodejs from 0.36.0 to a later version", async () => {
260262
await withDir(async (dir) => {
261263
// given
262264
const installDir = path.join(dir.path, "recipes");

0 commit comments

Comments
 (0)