Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compat mode in deno test #13227

Closed
Tracked by #12577
Soremwar opened this issue Dec 29, 2021 · 1 comment · Fixed by #13235
Closed
Tracked by #12577

Support compat mode in deno test #13227

Soremwar opened this issue Dec 29, 2021 · 1 comment · Fixed by #13235
Labels
node compat testing related to deno test and coverage

Comments

@Soremwar
Copy link
Contributor

As indicated by the title

This would be useful to run other test runners assertions under deno test and easing the migration of node codebases into Deno

Would be specially useful for deno_std, where the Node native tests are run as a subprocess instead of being run directly under compat mode (this is really annoying for local debugging, specially with average CPUs)

@Soremwar Soremwar mentioned this issue Dec 29, 2021
18 tasks
@bartlomieju bartlomieju added node compat testing related to deno test and coverage labels Dec 29, 2021
@bartlomieju
Copy link
Member

The first step is to update set up code for worker in cli/tools/test.rs:

deno/cli/tools/test.rs

Lines 455 to 460 in 42777f2

let mut worker = create_main_worker(
&ps,
specifier.clone(),
permissions,
vec![ops::testing::init(channel.clone())],
);

The setup will be mostly the same like in cli/main.rs:

deno/cli/main.rs

Lines 1154 to 1182 in 42777f2

if flags.compat {
// TODO(bartlomieju): fix me
assert_eq!(main_module.scheme(), "file");
// Set up Node globals
worker.execute_side_module(&compat::GLOBAL_URL).await?;
// And `module` module that we'll use for checking which
// loader to use and potentially load CJS module with.
// This allows to skip permission check for `--allow-net`
// which would otherwise be requested by dynamically importing
// this file.
worker.execute_side_module(&compat::MODULE_URL).await?;
let use_esm_loader = compat::check_if_should_use_esm_loader(&main_module)?;
if use_esm_loader {
// ES module execution in Node compatiblity mode
worker.execute_main_module(&main_module).await?;
} else {
// CJS module execution in Node compatiblity mode
compat::load_cjs_module(
&mut worker.js_runtime,
&main_module.to_file_path().unwrap().display().to_string(),
)?;
}
} else {
// Regular ES module execution
worker.execute_main_module(&main_module).await?;
}

Specifically this bit needs to be updated:

deno/cli/tools/test.rs

Lines 477 to 481 in 42777f2

// We only execute the specifier as a module if it is tagged with TestMode::Module or
// TestMode::Both.
if mode != TestMode::Documentation {
// We execute the module module as a side module so that import.meta.main is not set.
worker.execute_side_module(&specifier).await?;

I expect that we will need to tweak some type checking settings, as running multiple test files will cause to type check of deno_std/node multiple times, but it's a something that can be addressed in follow up PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node compat testing related to deno test and coverage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants