index.js 829 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { runCodeInTestContext } from "..";
  2. describe("helper-transform-fixture-test-runner", function() {
  3. it("should not execute code in Node's global context", function() {
  4. try {
  5. global.foo = "outer";
  6. runCodeInTestContext(
  7. `
  8. expect(global.foo).toBeUndefined();
  9. global.foo = "inner";
  10. `,
  11. {
  12. filename: `${__filename}.fake1`,
  13. },
  14. );
  15. expect(global.foo).toBe("outer");
  16. runCodeInTestContext(
  17. `
  18. expect(global.foo).toBe("inner");
  19. `,
  20. {
  21. filename: `${__filename}.fake2`,
  22. },
  23. );
  24. } finally {
  25. delete global.foo;
  26. runCodeInTestContext(
  27. `
  28. delete global.foo;
  29. `,
  30. {
  31. filename: `${__filename}.fake3`,
  32. },
  33. );
  34. }
  35. });
  36. });