11import assert from "node:assert/strict" ;
2- import { createRequire } from "node:module" ;
32import { DatabaseSync } from "node:sqlite" ;
43import { describe , test } from "node:test" ;
4+ import { sso } from "@better-auth/sso" ;
55import { betterAuth } from "better-auth" ;
66import { getMigrations } from "better-auth/db/migration" ;
77
8- const { sso } = createRequire ( import . meta. url ) ( "@better-auth/sso" ) ;
9-
108const TEST_CERT = `MIIDXTCCAkWgAwIBAgIJAOxEm08dOr3PMA0GCSqGSIb3DqEBCwUAMEUxCzAJBgNV
119BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
1210aWRnaXRzIFB0eSBMdGQwHhcNMjMwMTAxMDAwMDAwWhcNMjQwMTAxMDAwMDAwWjBF
@@ -29,6 +27,21 @@ r1PAFY+X3xF+5qDTbPpcHFPTIEWLpJFJPkSS+Q==`;
2927const IDP_ENTRY_POINT = "https://idp.example.com/saml2/sso" ;
3028
3129describe ( "SAML SSO" , ( ) => {
30+ /**
31+ * @see https://github.com/better-auth/better-auth/issues/8695
32+ *
33+ * samlify is a CJS module with __esModule: true but no exports.default.
34+ * Using `import saml from "samlify"` resolves to undefined in ESM,
35+ * causing `saml.setSchemaValidator(...)` to throw at module load time.
36+ * This test verifies that @better-auth/sso loads without error under ESM
37+ * by using a native ESM import (not createRequire).
38+ */
39+ test ( "should load @better-auth/sso via ESM without samlify import error" , async ( ) => {
40+ const mod = await import ( "@better-auth/sso" ) ;
41+ assert . ok ( mod . sso , "sso export should be defined" ) ;
42+ assert . equal ( typeof mod . sso , "function" , "sso should be a function" ) ;
43+ } ) ;
44+
3245 test ( "should generate SAML login request URL via defaultSSO" , async ( ) => {
3346 const database = new DatabaseSync ( ":memory:" ) ;
3447 const auth = betterAuth ( {
0 commit comments