diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index 18aa4b3b..aa3ec5a5 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -256,7 +256,9 @@ export class Extension { configure(options: Partial = {}) { this.options = mergeDeep(this.options, options) as Options - return this + // return a new instance so we can use the same extension + // with different calls of `configure` + return this.extend() } extend(extendedConfig: Partial> = {}) { diff --git a/packages/core/src/Mark.ts b/packages/core/src/Mark.ts index 1136dfdf..71f23ac9 100644 --- a/packages/core/src/Mark.ts +++ b/packages/core/src/Mark.ts @@ -353,7 +353,9 @@ export class Mark { configure(options: Partial = {}) { this.options = mergeDeep(this.options, options) as Options - return this + // return a new instance so we can use the same extension + // with different calls of `configure` + return this.extend() } extend(extendedConfig: Partial> = {}) { diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index 6f4b76cc..8caf936f 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -434,7 +434,9 @@ export class Node { configure(options: Partial = {}) { this.options = mergeDeep(this.options, options) as Options - return this + // return a new instance so we can use the same extension + // with different calls of `configure` + return this.extend() } extend(extendedConfig: Partial> = {}) { diff --git a/tests/cypress/integration/core/extensionOptions.spec.ts b/tests/cypress/integration/core/extensionOptions.spec.ts index 699ef0e2..ef8e4abd 100644 --- a/tests/cypress/integration/core/extensionOptions.spec.ts +++ b/tests/cypress/integration/core/extensionOptions.spec.ts @@ -121,4 +121,29 @@ describe('extension options', () => { }, }) }) + + it('should create its own instance on configure', () => { + const extension = Extension + .create({ + defaultOptions: { + foo: 1, + }, + }) + + const extension1 = extension.configure({ + foo: 2, + }) + + const extension2 = extension.configure({ + foo: 3, + }) + + expect(extension1.options).to.deep.eq({ + foo: 2, + }) + + expect(extension2.options).to.deep.eq({ + foo: 3, + }) + }) })