-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): cant run tests with external packages in non-entry files (#…
…4545) Tests output directories are now under the target directory. This closes #4394. Although there is still an issue where `require` doesn't respect the vm context, i think this makes sense since the current OS directories are temporary which increases the chances of lost terraform data and dangling cloud resources ## Checklist - [X] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [X] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
Showing
3 changed files
with
75 additions
and
6 deletions.
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
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,71 @@ | ||
import { describe, test, expect } from "vitest"; | ||
import { join, resolve, basename } from "path"; | ||
import { stat, mkdtemp } from "fs/promises"; | ||
import { tmpdir } from "os"; | ||
import { Target } from "./constants"; | ||
import { compile } from "./compile"; | ||
|
||
const exampleDir = resolve("../../examples/tests/valid"); | ||
const exampleFilePath = join(exampleDir, "enums.test.w"); | ||
|
||
export async function generateTmpDir() { | ||
return mkdtemp(join(tmpdir(), "-wing-compile-test")); | ||
} | ||
|
||
describe( | ||
"compile tests", | ||
() => { | ||
test("should produce stable artifacts for tf-aws", async () => { | ||
const targetDir = `${await generateTmpDir()}/target`; | ||
const artifactDir = await compile(exampleFilePath, { | ||
target: Target.TF_AWS, | ||
targetDir, | ||
}); | ||
|
||
const stats = await stat(artifactDir); | ||
expect(stats.isDirectory()).toBeTruthy(); | ||
expect(artifactDir).toContain(targetDir); | ||
expect(basename(artifactDir)).toEqual("enums.test.tfaws") | ||
}); | ||
|
||
test("should produce temp artifacts for tf-aws testing", async () => { | ||
const targetDir = `${await generateTmpDir()}/target`; | ||
const artifactDir = await compile(exampleFilePath, { | ||
target: Target.TF_AWS, | ||
targetDir, | ||
testing: true, | ||
}); | ||
|
||
const stats = await stat(artifactDir); | ||
expect(stats.isDirectory()).toBeTruthy(); | ||
expect(artifactDir).toContain(targetDir); | ||
expect(basename(artifactDir).match(/enums\.test\.tfaws\.\d+$/)).toBeTruthy(); | ||
}); | ||
|
||
test("should produce stable artifacts for sim", async () => { | ||
const targetDir = `${await generateTmpDir()}/target`; | ||
const artifactDir = await compile(exampleFilePath, { | ||
target: Target.SIM, | ||
targetDir, | ||
}); | ||
|
||
const stats = await stat(artifactDir); | ||
expect(stats.isDirectory()).toBeTruthy(); | ||
expect(artifactDir).toContain(targetDir); | ||
expect(basename(artifactDir)).toEqual("enums.test.wsim") | ||
}); | ||
|
||
test("should produce stable artifacts for sim testing", async () => { | ||
const targetDir = `${await generateTmpDir()}/target`; | ||
const artifactDir = await compile(exampleFilePath, { | ||
target: Target.SIM, | ||
targetDir, | ||
testing: true, | ||
}); | ||
|
||
const stats = await stat(artifactDir); | ||
expect(stats.isDirectory()).toBeTruthy(); | ||
expect(artifactDir).toContain(targetDir); | ||
expect(basename(artifactDir)).toEqual("enums.test.wsim") | ||
}); | ||
}); |
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