Skip to content

Commit

Permalink
fix: handle unintentional floating promises (#4947)
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Oct 8, 2022
1 parent a34a7d5 commit abe52fe
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 15 deletions.
34 changes: 34 additions & 0 deletions .yarn/versions/99c1aeb7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/plugin-essentials": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe(`Commands`, () => {
}));

test(`test apply fix to string fields`, makeTemporaryEnv(manifest, config, async ({path, run, source}) => {
environments[`various field types`](path);
await environments[`various field types`](path);

await xfs.writeFilePromise(`${path}/constraints.pro`, `
gen_enforced_field(WorkspaceCwd, '_name', FieldValue) :- workspace_field(WorkspaceCwd, 'name', FieldValue).
Expand All @@ -105,7 +105,7 @@ describe(`Commands`, () => {
}));

test(`test apply fix to object fields`, makeTemporaryEnv(manifest, config, async ({path, run, source}) => {
environments[`various field types`](path);
await environments[`various field types`](path);

await xfs.writeFilePromise(`${path}/constraints.pro`, `
gen_enforced_field(WorkspaceCwd, '_repository', FieldValue) :- workspace_field(WorkspaceCwd, 'repository', FieldValue).
Expand All @@ -123,7 +123,7 @@ describe(`Commands`, () => {
}));

test(`test apply fix to array fields`, makeTemporaryEnv(manifest, config, async ({path, run, source}) => {
environments[`various field types`](path);
await environments[`various field types`](path);

await xfs.writeFilePromise(`${path}/constraints.pro`, `
gen_enforced_field(WorkspaceCwd, '_files', FieldValue) :- workspace_field(WorkspaceCwd, 'files', FieldValue).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe(`Commands`, () => {

await run(`install`);

expect(run(`workspace`, `pkg-primary`, `version`, `patch`)).resolves.toMatchObject({
await expect(run(`workspace`, `pkg-primary`, `version`, `patch`)).resolves.toMatchObject({
code: 0,
stdout: expect.stringContaining(`Couldn't auto-upgrade range * (in pkg-dependant@workspace:packages/pkg-dependant)`),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ describe(`Node_Modules`, () => {
await run(`install`);

const binPath = `${path}/node_modules/.bin/dep1` as PortablePath;
expect(xfs.lstatPromise(binPath)).resolves.toBeDefined();
await expect(xfs.lstatPromise(binPath)).resolves.toBeDefined();
await run(`remove`, `dep1`);
expect(xfs.lstatPromise(binPath)).rejects.toBeDefined();
await expect(xfs.lstatPromise(binPath)).rejects.toBeDefined();
},
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ describe(`Plug'n'Play`, () => {

await run2(`install`);

expect(readFile(`${path2}/.pnp.cjs`, `utf8`)).resolves.toEqual(await readFile(`${path}/.pnp.cjs`, `utf8`));
await expect(readFile(`${path2}/.pnp.cjs`, `utf8`)).resolves.toEqual(await readFile(`${path}/.pnp.cjs`, `utf8`));
},
)();
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-essentials/sources/dedupeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export async function dedupe(project: Project, {strategy, patterns, cache, repor
const dedupePromises = await algorithm(project, patterns, {resolver, resolveOptions, fetcher, fetchOptions});

const progress = Report.progressViaCounter(dedupePromises.length);
report.reportProgress(progress);
await report.reportProgress(progress);

let dedupedPackageCount = 0;

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ export class Project {
let firstError = false;

const progress = Report.progressViaCounter(locatorHashes.length);
report.reportProgress(progress);
await report.reportProgress(progress);

const limit = pLimit(FETCHER_CONCURRENCY);

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-fslib/tests/JailFS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe(`JailFS`, () => {
await xfs.mkdirPromise(jailedFolder);

const jailFs = new JailFS(jailedFolder);
jailFs.writeFilePromise(ppath.join(PortablePath.root, `text.txt` as Filename), `Hello World`);
await jailFs.writeFilePromise(ppath.join(PortablePath.root, `text.txt` as Filename), `Hello World`);
});

it(`should throw an error when the accessed path is not inside the target folder`, async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-fslib/tests/NodeFS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe(`NodeFS`, () => {
});

it(`should support ftruncateSync`, () => {
xfs.mktempSync(async dir => {
xfs.mktempSync(dir => {
const p = `${dir}/foo.txt` as PortablePath;
nodeFs.writeFileSync(p, `foo`);

Expand Down
6 changes: 3 additions & 3 deletions packages/yarnpkg-fslib/tests/ZipFS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe(`ZipFS`, () => {
const tmpfile = ppath.resolve(xfs.mktempSync(), `test.zip` as Filename);
const zipFs = new ZipFS(tmpfile, {libzip, create: true});

zipFs.mkdirPromise(`/dir` as PortablePath);
zipFs.mkdirSync(`/dir` as PortablePath);
zipFs.writeFileSync(`/dir/file` as PortablePath, `file content`);

zipFs.symlinkSync(`dir/file` as PortablePath, `linkToFileA` as PortablePath);
Expand Down Expand Up @@ -863,13 +863,13 @@ describe(`ZipFS`, () => {
it(`should support fd in writeFile and readFile`, async () => {
const zipFs = new ZipFS(null, {libzip: getLibzipSync()});

zipFs.mkdirPromise(`/dir` as PortablePath);
zipFs.mkdirSync(`/dir` as PortablePath);
zipFs.writeFileSync(`/dir/file` as PortablePath, `file content`);

const fd = zipFs.openSync(`/dir/file` as PortablePath, `r`);
zipFs.writeFileSync(fd, `new content`);

expect(zipFs.readFilePromise(fd, `utf8`)).resolves.toEqual(`new content`);
await expect(zipFs.readFilePromise(fd, `utf8`)).resolves.toEqual(`new content`);

await zipFs.writeFilePromise(fd, `new new content`);

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-fslib/tests/xfs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe(`xfs`, () => {
return t;
});

xfs.rmtempPromise();
await xfs.rmtempPromise();

await expect(xfs.existsPromise(temp)).resolves.toBe(true);
await expect(xfs.existsPromise(otherTemp)).resolves.toBe(true);
Expand Down

0 comments on commit abe52fe

Please sign in to comment.