Skip to content

Commit

Permalink
Revamp snapshot tests (vercel#2351)
Browse files Browse the repository at this point in the history
* Disable HMR for snapshot tests

The only effect is that we don't emit source maps for the individual chunk items, reducing the total number of output files considerably.

* Extract snapshot tests into separate crate

* Strip annoying file hash fingerprints

* Reduce deps

* Update old references to turbopack/test/snapshot

* Move node_modules out of snapshot dir

* Only un-fingerprint EcmascriptChunkSourceMapAssetVc source maps

* Fix gitignore

* Remove dbg

* TAPLO

* Apply suggestions from code review

Co-authored-by: Alex Kirszenberg <[email protected]>

* Use eprintln

Co-authored-by: Alex Kirszenberg <[email protected]>
  • Loading branch information
jridgewell and alexkirsz authored Oct 28, 2022
1 parent c9a563e commit e7815fd
Show file tree
Hide file tree
Showing 301 changed files with 484 additions and 1,002 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
crates/turbopack/tests/snapshot/*/output/** linguist-generated=true
crates/turbopack-tests/tests/snapshot/**/output/** linguist-generated=true
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ graph*.html
.pnp.*
.yarn/*

# include everything in the snapshots dir
!crates/turbopack/tests/snapshot/**

# generated by cargo xtask publish
packages/node-module-trace/npm
artifacts
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dist/
node_modules/
target/

/crates/turbopack/tests/snapshot/**/output/
/crates/turbopack-tests/tests/snapshot/**/output/
/examples/with-svelte

pnpm-lock.yaml
Expand Down
41 changes: 37 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ members = [
"crates/turbopack-static",
"crates/turbopack-swc-utils",
"crates/turbopack",
"crates/turbopack-tests",
"xtask",
]

Expand Down
4 changes: 2 additions & 2 deletions crates/turbo-tasks-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ pub fn generate_register() {
}
}

pub fn rerun_if_glob(globs: &str) {
pub fn rerun_if_glob(globs: &str, root: &str) {
let cwd = env::current_dir().unwrap();
let globs = cwd.join(globs);
let mut seen = HashSet::from([cwd.as_path().to_owned()]);
let mut seen = HashSet::from([cwd.join(root)]);
for entry in glob(globs.to_str().unwrap()).unwrap() {
let path = entry.unwrap();
for ancestor in path.ancestors() {
Expand Down
1 change: 0 additions & 1 deletion crates/turbopack-ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ version = "0.4"

[dev-dependencies]
criterion = { version = "0.3.5", features = ["async_tokio"] }
difference = "2.0"
rstest = "0.12.0"
turbo-tasks-memory = { path = "../turbo-tasks-memory" }
turbo-tasks-testing = { path = "../turbo-tasks-testing" }
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-ecmascript/src/chunk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod loader;
pub(crate) mod optimize;
pub(crate) mod source_map;
pub mod source_map;

use std::{fmt::Write as _, slice::Iter};

Expand Down
30 changes: 30 additions & 0 deletions crates/turbopack-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "turbopack-tests"
version = "0.1.0"
description = "TBD"
license = "MPL-2.0"
edition = "2021"
autobenches = false

# don't publish this crate
publish = false

[dev-dependencies]
anyhow = "1.0.47"
once_cell = "1.13.0"
serde = "1.0.136"
serde_json = "1.0.85"
similar = "2.2.0"
test-generator = "0.3.0"
tokio = "1.11.0"
turbo-tasks = { path = "../turbo-tasks" }
turbo-tasks-env = { path = "../turbo-tasks-env" }
turbo-tasks-fs = { path = "../turbo-tasks-fs" }
turbo-tasks-memory = { path = "../turbo-tasks-memory" }
turbopack = { path = "../turbopack" }
turbopack-core = { path = "../turbopack-core" }
turbopack-ecmascript = { path = "../turbopack-ecmascript" }
turbopack-env = { path = "../turbopack-env" }

[build-dependencies]
turbo-tasks-build = { path = "../turbo-tasks-build" }
26 changes: 26 additions & 0 deletions crates/turbopack-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# turbopack-tests

An extracted create to perform snapshot tests on turbopack.

## Testing

It's possible to only run the snapshot tests using [nextest][]'s filter
expressions:

```bash
cargo nextest run -E 'test(snapshot)'
```

The filter supports any substring, and only test names which contain
that substring will run.

## Updating Snapshot

If you've made a change that requires many snapshot updates, you can
automatically update all outputs using the `UPDATE` command line env:

```bash
UPDATE=1 cargo nextest run -E 'test(snapshot)'
```

[nextest]: https://nexte.st/
9 changes: 9 additions & 0 deletions crates/turbopack-tests/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use turbo_tasks_build::{generate_register, rerun_if_glob};

fn main() {
generate_register();
// The test/snapshot crate need to be rebuilt if any snapshots are added.
// Unfortunately, we can't have the build.rs file operate differently on
// each file, so the entire turbopack crate needs to be rebuilt.
rerun_if_glob("tests/snapshot/*/*", "test/snapshot");
}
File renamed without changes.
4 changes: 4 additions & 0 deletions crates/turbopack-tests/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
# include everything in the snapshots dir
!snapshot/**

File renamed without changes.
Loading

0 comments on commit e7815fd

Please sign in to comment.