-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a helper function to destroy an array of resources
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@open-pioneer/core": minor | ||
--- | ||
|
||
Add `destroyResources(resources)` to destroy an array of resources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer) | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { expect, it } from "vitest"; | ||
import { destroyResources, Resource } from "./resources"; | ||
|
||
it("destroys all resources in the array", () => { | ||
const events: string[] = []; | ||
const resources: Resource[] = [ | ||
{ | ||
destroy() { | ||
events.push("destroyed 1"); | ||
} | ||
}, | ||
{ | ||
destroy() { | ||
events.push("destroyed 2"); | ||
} | ||
} | ||
]; | ||
|
||
destroyResources(resources); | ||
expect(events).toEqual(["destroyed 2", "destroyed 1"]); // reverse order | ||
}); | ||
|
||
it("handles cycles correctly", () => { | ||
const events: string[] = []; | ||
const resources: Resource[] = [ | ||
{ | ||
destroy() { | ||
events.push("destroyed 1"); | ||
destroyResources(resources); // still only destroys each resource only once | ||
} | ||
}, | ||
{ | ||
destroy() { | ||
events.push("destroyed 2"); | ||
} | ||
} | ||
]; | ||
|
||
destroyResources(resources); | ||
expect(events).toEqual(["destroyed 2", "destroyed 1"]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters