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

bun preloader for test #341

Open
xxleyi opened this issue May 20, 2023 · 0 comments
Open

bun preloader for test #341

xxleyi opened this issue May 20, 2023 · 0 comments

Comments

@xxleyi
Copy link
Owner

xxleyi commented May 20, 2023

// happy-dom
import { GlobalRegistrator  } from '@happy-dom/global-registrator';
GlobalRegistrator.register();

// global test lifecycle hooks
import { cleanup } from '@testing-library/react'
import { beforeAll, beforeEach, afterEach, afterAll } from "bun:test";
beforeAll(() => {
    console.log('before all, only run once')
})
afterEach(() => {
    console.log('after each')
    cleanup()
})

// custom loader for any file type, for test stub
const stubLessPlugin = {
    name: "less loader",
    async setup(build) {
      const { readFileSync } = await import("fs");

      // implementation
      build.onLoad({ filter: /\.(less)$/ }, (args) => {
        const text = readFileSync(args.path, "utf8");
        console.log('text\n', text, '\n', args.path);
        const exports = {};
  
        // and returns it as a module
        return {
          exports,
          loader: "object", // special loader for JS objects
        };
      });
    },
  };

Bun.plugin(stubLessPlugin);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant