fix: fix some tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { rewriteAllObservableSubscribeToLastValueFrom } from './code-transform';
|
||||
import { rewriteAllObservableSubscribeTofirstValueFrom } from './code-transform';
|
||||
|
||||
const program = new Command();
|
||||
|
||||
@@ -13,7 +13,7 @@ program
|
||||
.command('rewrite <pattern>')
|
||||
.description('Rewrite files matching the given glob pattern')
|
||||
.action(async (pattern: string) => {
|
||||
await rewriteAllObservableSubscribeToLastValueFrom(pattern);
|
||||
await rewriteAllObservableSubscribeTofirstValueFrom(pattern);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { Biome, Distribution } from '@biomejs/js-api';
|
||||
import { rewriteObservableSubscribeToLastValueFrom } from './code-transform';
|
||||
import { rewriteObservableSubscribeTofirstValueFrom } from './code-transform';
|
||||
|
||||
describe('rewriteSpecObservableSubscribeToLastValueFrom', () => {
|
||||
describe('rewriteSpecObservableSubscribeTofirstValueFrom', () => {
|
||||
it('should transform simple example valid string', async () => {
|
||||
const actual = await rewriteObservableSubscribeToLastValueFrom(
|
||||
const actual = await rewriteObservableSubscribeTofirstValueFrom(
|
||||
'index.ts',
|
||||
`refreshSessionIframeService
|
||||
.refreshSessionWithIframe(allConfigs[0]!, allConfigs)
|
||||
@@ -20,7 +20,7 @@ describe('rewriteSpecObservableSubscribeToLastValueFrom', () => {
|
||||
});`
|
||||
);
|
||||
|
||||
const expect = `const result = await lastValueFrom(refreshSessionIframeService.refreshSessionWithIframe(allConfigs[0]!, allConfigs));
|
||||
const expect = `const result = await firstValueFrom(refreshSessionIframeService.refreshSessionWithIframe(allConfigs[0]!, allConfigs));
|
||||
expect(result).toHaveBeenCalledExactlyOnceWith('a-url',allConfigs[0]!,allConfigs);`;
|
||||
|
||||
const biome = await Biome.create({
|
||||
@@ -34,7 +34,7 @@ describe('rewriteSpecObservableSubscribeToLastValueFrom', () => {
|
||||
});
|
||||
|
||||
it('should rewrite complex exmaple to valid string', async () => {
|
||||
const actual = await rewriteObservableSubscribeToLastValueFrom(
|
||||
const actual = await rewriteObservableSubscribeTofirstValueFrom(
|
||||
'index.ts',
|
||||
`codeFlowCallbackService
|
||||
.authenticatedCallbackWithCode('some-url4', config, [config])
|
||||
@@ -56,7 +56,7 @@ describe('rewriteSpecObservableSubscribeToLastValueFrom', () => {
|
||||
|
||||
const expect = `
|
||||
try {
|
||||
const abc = await lastValueFrom(codeFlowCallbackService.authenticatedCallbackWithCode('some-url4', config, [config]));
|
||||
const abc = await firstValueFrom(codeFlowCallbackService.authenticatedCallbackWithCode('some-url4', config, [config]));
|
||||
expect(abc).toBeTruthy();
|
||||
} catch (err: any) {
|
||||
if (err instanceof EmptyError) {
|
||||
|
||||
@@ -21,7 +21,7 @@ function sourceTextFromNode(
|
||||
return magicString.getSourceText(start, end);
|
||||
}
|
||||
|
||||
export async function rewriteObservableSubscribeToLastValueFrom(
|
||||
export async function rewriteObservableSubscribeTofirstValueFrom(
|
||||
filename: string,
|
||||
content?: string
|
||||
) {
|
||||
@@ -83,7 +83,7 @@ export async function rewriteObservableSubscribeToLastValueFrom(
|
||||
error = args[1];
|
||||
complete = args[2];
|
||||
}
|
||||
let newContent = `await lastValueFrom(${sourceTextFromNode(context, child.expression.callee.object)});`;
|
||||
let newContent = `await firstValueFrom(${sourceTextFromNode(context, child.expression.callee.object)});`;
|
||||
|
||||
if (next) {
|
||||
const nextParam =
|
||||
@@ -161,12 +161,12 @@ export async function rewriteObservableSubscribeToLastValueFrom(
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function rewriteAllObservableSubscribeToLastValueFrom(
|
||||
export async function rewriteAllObservableSubscribeTofirstValueFrom(
|
||||
pattern: string | string[]
|
||||
) {
|
||||
const files = fsp.glob(pattern);
|
||||
for await (const file of files) {
|
||||
const result = await rewriteObservableSubscribeToLastValueFrom(file);
|
||||
const result = await rewriteObservableSubscribeTofirstValueFrom(file);
|
||||
|
||||
await fsp.writeFile(file, result, 'utf-8');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user