(t *testing.T)
| 641 | } |
| 642 | |
| 643 | func TestModuleBuilder_ErrorBranches(t *testing.T) { |
| 644 | useStableOwnerHooksForLegacySubtests(t) |
| 645 | |
| 646 | rt := NewRuntime() |
| 647 | defer rt.Close() |
| 648 | ctx := rt.NewContext() |
| 649 | defer ctx.Close() |
| 650 | |
| 651 | t.Run("ModuleInitContextError", func(t *testing.T) { |
| 652 | // Create module |
| 653 | module := NewModuleBuilder("error-test-1"). |
| 654 | Export("value", ctx.NewString("test")) |
| 655 | err := module.Build(ctx) |
| 656 | require.NoError(t, err) |
| 657 | |
| 658 | // Unregister context before module initialization |
| 659 | unregisterContext(ctx.ref) |
| 660 | |
| 661 | // Import will fail during initialization |
| 662 | result := ctx.Eval(`import('error-test-1')`, EvalAwait(true)) |
| 663 | defer result.Free() |
| 664 | |
| 665 | // Re-register for cleanup |
| 666 | registerContext(ctx.ref, ctx) |
| 667 | |
| 668 | // Should get context error |
| 669 | require.True(t, result.IsException()) |
| 670 | err = ctx.Exception() |
| 671 | require.Contains(t, err.Error(), "Context not found") |
| 672 | }) |
| 673 | |
| 674 | t.Run("ModuleInitHandleStoreError", func(t *testing.T) { |
| 675 | // Create module |
| 676 | module := NewModuleBuilder("error-test-2"). |
| 677 | Export("value", ctx.NewString("test")) |
| 678 | err := module.Build(ctx) |
| 679 | require.NoError(t, err) |
| 680 | |
| 681 | // Clear handle store before module initialization |
| 682 | ctx.handleStore.Clear() |
| 683 | |
| 684 | // Import will fail during initialization |
| 685 | result := ctx.Eval(`import('error-test-2')`, EvalAwait(true)) |
| 686 | defer result.Free() |
| 687 | |
| 688 | // Should get handle store error |
| 689 | require.True(t, result.IsException()) |
| 690 | err = ctx.Exception() |
| 691 | require.Contains(t, err.Error(), "Function not found") |
| 692 | }) |
| 693 | |
| 694 | t.Run("ModuleInitUsesBuildSnapshot", func(t *testing.T) { |
| 695 | fooFunc := ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value { |
| 696 | return ctx.NewUndefined() |
| 697 | }) |
| 698 | defer fooFunc.Free() |
| 699 | |
| 700 | module := NewModuleBuilder("error-test-3").Export("foo", fooFunc) |
nothing calls this directly
no test coverage detected