Skip to content

Commit d418f79

Browse files
committed
test: fix tests to account for rxjs observable replacing callbacks
1 parent 4041208 commit d418f79

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

test/index.spec.ts

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {readFileSync} from "fs";
33
import {TestBed, readFixtures, mergeOptionsForTmpFile} from "./test-utils";
44

55
import {main} from "../src/index";
6+
import {lastValueFrom, tap} from "rxjs";
67

78
const LIBRARY_NAME = require("../package.json").name;
89
const fixtures = readFixtures();
@@ -15,28 +16,17 @@ describe(LIBRARY_NAME, () => {
1516
});
1617

1718
fixtures.forEach(fixture => {
18-
it(fixture.fixtureName, done => {
19+
it(fixture.fixtureName, async () => {
1920
expect.assertions(1);
2021
testBed.prepareFixtureInTmpDirectory(fixture);
2122
const tmpFile = testBed.getTmpFileForFixture(fixture);
2223
const options = mergeOptionsForTmpFile(
2324
{checkOnly: false, filesWhitelist: null},
2425
tmpFile
2526
);
26-
main(tmpFile.directoryPath, options, {
27-
onInit() {},
28-
onBegunProcessingFile() {},
29-
onModifiedFilesDetected() {},
30-
onFinishedProcessingFile() {},
31-
onComplete() {
32-
const formatted = readFileSync(tmpFile.path, "utf8");
33-
expect(formatted).toMatchSnapshot();
34-
done();
35-
},
36-
onError(err) {
37-
done(err);
38-
}
39-
});
27+
await lastValueFrom(main(tmpFile.directoryPath, options));
28+
const formatted = readFileSync(tmpFile.path, "utf8");
29+
expect(formatted).toMatchSnapshot();
4030
});
4131
});
4232
});
@@ -47,28 +37,23 @@ describe(LIBRARY_NAME, () => {
4737
});
4838

4939
fixtures.forEach(fixture => {
50-
it(fixture.fixtureName, done => {
40+
it(fixture.fixtureName, async () => {
5141
expect.assertions(1);
5242
testBed.prepareFixtureInTmpDirectory(fixture);
5343
const tmpFile = testBed.getTmpFileForFixture(fixture);
5444
const options = mergeOptionsForTmpFile(
5545
{checkOnly: true, filesWhitelist: null},
5646
tmpFile
5747
);
58-
main(tmpFile.directoryPath, options, {
59-
onInit() {},
60-
onBegunProcessingFile() {},
61-
onModifiedFilesDetected() {},
62-
onFinishedProcessingFile(_fn, _i, status) {
63-
expect(status).toEqual("INVALID_FORMATTING");
64-
},
65-
onComplete() {
66-
done();
67-
},
68-
onError(err) {
69-
done(err);
70-
}
71-
});
48+
await lastValueFrom(
49+
main(tmpFile.directoryPath, options).pipe(
50+
tap(event => {
51+
if (event.event === "FinishedProcessingFile") {
52+
expect(event.status).toEqual("INVALID_FORMATTING");
53+
}
54+
})
55+
)
56+
);
7257
});
7358
});
7459
});

0 commit comments

Comments
 (0)