Files
bun.sh/test
Hyro 7a734e0a28 feat: implement native os module (#1115)
* feat: implement os module

* revert(bun-error): package-lock.json

* feat: implement EOL

* feat: implement EOL

* feat: implement arch function

* feat: implement homedir function

* add comptime to homedir if

* feat: add platform function

* feat: implement type function

* feat: add hostname (not sure iff works on all platforms)

* chore: make requested changes

* fix: change toValueGC into toValue in arch function

* add EOL, devNull constant variables

* fix: store only string

* feat: add tests

* feat: add endianness

* ususe toValue for devNull & EOL

* feat: implement endianness & fix release

* revert javascript.zig fix

* feat: implement tmpdir

* feat: implement totalmem, freemem, uptime

* feat: loadavg

* feat: implement version

* feat: add userInfo

* feat: implement totalmem for macos

* feat: add getPriority (not finished, waiting for dc response)

* feat: finish userInfo implementation

* feat: implement cpus, not done

* feat: finish getPriority implementation & stats cpus()

* feat: implement setPriority

* reemove test.c

* feat: implement constants.dlope.xn, constants.priority.x, constants.UV_UDP_REUSEADDR

* feat: implement signals, errno

* updated cpus function, stilldoesnt work

* increase object length

* feat: add t more ests

* feat: add cpus()

* remov some files

* fix: handle empty array

* started working on interface addresses (in C)

ill use C++ after it work

* fix interface_addresses

* Improved getCpuInfo code, decreased ram usage, increased speed

* getCpuTime optimizations

* started working on networkInterfaces

* feat: networkInterfaces implementation

* delete unnecessary files

* add benchs & fix code

* add tests

* add missing benchs

* Increased buffer of getCpuInfo to 2048, it should skip few iterations

* remove hardcoded constants

* feat: implement errno constants

* fix getWindowsErrorConstant

* feat: add signal constants

* feat: implement priority constants

* remove duplications

* fix: change value to ?i16

* fix(__defineConstant): make some parameters comptime, change value to ?i32

* fix: add E to ERRNO constants, add SIG to SIG constants

* feat: add dlopen constants

* change functions to private

* feat: add UV_UDP_REUSEADDR

* fix typo

* simplify functions

* rename functions in bindings

* feat: implement loadavg for darwin

* feat: implement system uptime

* feat: implement get free memory for darwin

* fix system memory bindings

* feat: implement network interfaces for darwin

* code cleanup

* feat: support for macos version & release

* some fixes

* MacOS support for CpuInfo

* Fixed minor mistake in getCpuInfo_B

* Delete test.zig

* Update c_cpp_properties.json

* Update tasks.json

* feat: implement scopeid

* feat: implement cidr 🚀

* remove unnecesarry changes

* remove unnecesarry changes

* chore: requested changes

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* chore: requested changes

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* chore: requested changes

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* chore: requested changes

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* chore: requested changes

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* chore: requested changes

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* chore: requested changes

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* fix: import string

* fix: change IPV6 to IPv6

* fix some things

* chore: make requested changes

* revert: launch.json

* fix test

* Fixed few memory leaks

* testing

* again

* added len

* another test

* improved parsing

* added small check

* Bonk

* FINISH 🚀🚀🚀🚀🚀🚀

* Update tasks.json

* NetworkInterface test

* FINISH 🚀🚀🚀

Co-authored-by: Fire-The-Fox <gajdos.jan77@gmail.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2022-08-25 19:38:28 -07:00
..
2022-08-19 00:35:26 -07:00
2022-08-07 23:28:10 -07:00
2022-06-22 23:21:48 -07:00
2022-07-09 05:09:16 -07:00
2022-07-09 05:09:16 -07:00
2022-07-09 05:09:16 -07:00
2022-06-22 23:21:48 -07:00

Tests in Bun

Bun currently has four different kinds of tests

To run the tests:

make test-all
bun wiptest

Browser tests

Browser tests run end-to-end inside of Puppeteer and execute code transpiled by bun dev. These tests are in ./snippets.

The interface is:

// this function is called after import()
// if testDone() is never called, the test fails
export function test() {
  return testDone(import.meta.url);
}

On success, it saves a snapshot to ./snapshots which is checked into git.

Adding a new test

  1. Create a new file in the snippets directory.
  2. Append the filename to ./scripts/snippets.json
  3. Run bun dev inside this folder in one terminal window
  4. Run make integration-test-dev

These tests are run twice. Once with HMR enabled and once with HMR disabled. HMR changes the output enough to warrant it's own special treatment.

Running the tests

To run the browser tests with HMR on a production build:

make test-with-hmr

To run the browser tests without HMR on a production build:

make test-with-no-hmr

To run the browser tests with HMR on a debug build:

make test-dev-with-hmr

To run the browser tests without HMR on a debug build:

make test-dev-no-hmr

To run the browser tests on whatever version of bun is running on port 3000:

make integration-test-dev

These were the first tests bun started with

Runtime tests

These tests are in ./bun.js and are files which are either .test.js or .test.ts files.

These test that the runtime behaves as expected. These also test the transpiler, both because test files are transpiled and directly by running the transpiler via Bun.Transpiler.

Adding a new test

  1. Create a new file in ./bun.js with .test in the name.

These test use bun:test as the import (though you can also import from vitest or jest and it will work).

This will eventually be a public test runner for bun, but the reporter isn't very good yet and it doesn't run in parallel.

The syntax intends for Jest compatibility.

import { describe, expect, it } from "bun:test";

describe("Example", () => {
  it("should work", () => {
    expect(1).toBe(1);
  });
});

Running the tests

Run bun wiptest ${part-of-file-name}

If you run the test in the top-level bun repo directory, it will take an extra couple seconds because bun wiptest will scan through all of WebKit recursively. Consider running it in the bun.js directory instead.

CLI tests

These run the bash files in the apps directory.

They check end-to-end that the CLI works as expected.

# Install dependencies for running tests
# Does not run tests
make test-install

# Check a Create React App created via `bun create react ./foo` returns HTML
make test-create-react

# Check a Next.js app created via `bun create next ./foo` SSRs successfully
make test-create-next

# Check that bun run works for the same CLI args passed to npm run
make test-bun-run

# Check that "react" installed via bun install loads successfully
# and that deleting/adding updates the lockfile as expected
make test-bun-install

# Check that serving public paths works correctly
# and that files which should be transpiled are transpiled and files which shouldn't be aren't
make test-bun-dev

Zig tests

These tests live in various .zig files throughout Bun's codebase, leveraging Zig's builtin test keyword.

Currently, they're not run automatically nor is there a simple way to run all of them.

This is an area bun needs to improve in.