Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Async-ified linterTests.ts #3338

Closed
wants to merge 1 commit into from
Closed

Async-ified linterTests.ts #3338

wants to merge 1 commit into from

Conversation

JoshuaKGoldberg
Copy link
Contributor

PR checklist

Overview of change:

Uses asynchronous file reading & writing. Very mild performance boost for writing the test's temp files in parallel.

const sourceFile = createSourceFile(templateFile, `${templateDeclaration}`, ScriptTarget.ES2015);
const replacement = new Replacement(6, 9, "");
const failure = new RuleFailure(sourceFile, 6, 15, "Declaration doesn't exist", "foo-bar", replacement);
linter.applyFixesHelper(componentFile, componentDeclaration(templateFile), [failure]);
assert.equal(fs.readFileSync(templateFile, "utf-8"), templateDeclarationFixed);

const actualTemplateFileContents = await readFileAsync(templateFile, "utf-8");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one makes no sense to be async and awaited immediately

@@ -213,3 +215,27 @@ export function detectBufferEncoding(buffer: Buffer, length = buffer.length): En
export function denormalizeWinPath(path: string): string {
return path.replace(/\\/g, "/");
}

export async function readFileAsync(fileName: string, encoding: string): Promise<string> {
return await new Promise<string>((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the other PR: remove the await here

}

export async function writeFileAsync(fileName: string, data: string): Promise<void> {
await new Promise<void>((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the other PR: replace await with return

@JoshuaKGoldberg
Copy link
Contributor Author

JoshuaKGoldberg commented Oct 23, 2017

this one makes no sense to be async and awaited immediately

(discussion in #3333)

I'll just rescind. Thanks for the review!

@JoshuaKGoldberg JoshuaKGoldberg deleted the linter-tests-async branch October 23, 2017 05:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants