Skip to content

Commit

Permalink
chore: update an integration test and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nyannyacha committed Oct 16, 2024
1 parent 3045eaf commit 862f128
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/base/test_cases/main_eszip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Deno.serve(async (req: Request) => {
const workerTimeoutMs = 10 * 60 * 1000;
const cpuTimeSoftLimitMs = 10 * 60 * 1000;
const cpuTimeHardLimitMs = 10 * 60 * 1000;
const noModuleCache = false;
const noModuleCache = true;
const importMapPath = null;
const envVarsObj = Deno.env.toObject();
const envVars = Object.keys(envVarsObj).map(k => [k, envVarsObj[k]]);
Expand Down
8 changes: 6 additions & 2 deletions crates/base/test_cases/main_with_registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ Deno.serve(async (req: Request) => {
const url = new URL(req.url);
const { pathname } = url;
const path_parts = pathname.split("/");
const service_name = path_parts[1];
let service_name = path_parts[1];

if (req.headers.has('x-service-path')) {
service_name = req.headers.get('x-service-path')!;
}

const REGISTRY_PREFIX = '/_internal/registry';
if (pathname.startsWith(REGISTRY_PREFIX)) {
Expand All @@ -30,7 +34,7 @@ Deno.serve(async (req: Request) => {
const workerTimeoutMs = 10 * 60 * 1000;
const cpuTimeSoftLimitMs = 10 * 60 * 1000;
const cpuTimeHardLimitMs = 10 * 60 * 1000;
const noModuleCache = false;
const noModuleCache = true;
const importMapPath = null;
const envVarsObj = Deno.env.toObject();
const envVars = Object.keys(envVarsObj).map(k => [k, envVarsObj[k]]);
Expand Down
2 changes: 2 additions & 0 deletions crates/base/test_cases/private-npm-package-import-2/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@meowmeow:registry=http://localhost:8498/_internal/registry/
//localhost:8498/_internal/registry/:_authToken=MeowMeowToken
13 changes: 13 additions & 0 deletions crates/base/test_cases/private-npm-package-import-2/inner/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import foobar from "npm:@meowmeow/foobar";
import isOdd from "npm:is-odd";

console.log(foobar());

export default {
fetch() {
return Response.json({
meow: typeof foobar,
odd: isOdd(1),
});
}
}
27 changes: 27 additions & 0 deletions crates/base/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,33 @@ async fn test_private_npm_package_import() {
handle.await.unwrap();
}

{
let token = TerminationToken::new();
let handle = run_server_fn("./test_cases/main_with_registry", token.clone()).await;

let resp = client
.request(
Method::GET,
format!("http://localhost:{}/meow", NON_SECURE_PORT),
)
.header("x-service-path", "private-npm-package-import-2/inner")
.send()
.await
.unwrap();

assert_eq!(resp.status().as_u16(), 200);

let body = resp.json::<serde_json::Value>().await.unwrap();
let body = body.as_object().unwrap();

assert_eq!(body.len(), 2);
assert_eq!(body.get("meow"), Some(&json!("function")));
assert_eq!(body.get("odd"), Some(&json!(true)));

token.cancel();
handle.await.unwrap();
}

{
let token = TerminationToken::new();
let handle = run_server_fn("./test_cases/main_eszip", token.clone()).await;
Expand Down

0 comments on commit 862f128

Please sign in to comment.