Skip to content

Only allow enablePrivateMethod to be true for lightning & interop namespaces#420

Merged
a-chabot merged 17 commits intosalesforce:masterfrom
a-chabot:a-chabot/add-private-methods-flag
Apr 15, 2026
Merged

Only allow enablePrivateMethod to be true for lightning & interop namespaces#420
a-chabot merged 17 commits intosalesforce:masterfrom
a-chabot:a-chabot/add-private-methods-flag

Conversation

@a-chabot
Copy link
Copy Markdown
Collaborator

No description provided.

a-chabot and others added 11 commits March 26, 2026 14:39
Enable private methods support in LWC jest transformer by adding the enablePrivateMethods flag to compiler options.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Upgrade LWC packages from 9.0.3 to 9.1.0 for private methods support
- Add integration tests for private methods feature
- Tests verify that private methods work correctly within LWC components

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace Salesforce internal Nexus proxy URLs with public npm registry URLs to fix CI failures.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Resolve jest-transformer index.js: keep conditional enablePrivateMethods
(lightning/interop) instead of upstream always-true. Omit smoke/privateMethods
fixture re-added upstream; lightning/privateMethods remains the integration target.

Made-with: Cursor
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
describe('private methods', () => {
it('should allow calling private methods from public methods', () => {
const element = createElement('smoke-private-methods', { is: PrivateMethods });
const element = createElement('lightning-private-methods', { is: PrivateMethods });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test both smoke-private-methods and lightning-private-methods, since they'll behave differently?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

Comment on lines +7 to +21
jest.mock('@lwc/compiler/dist/index.cjs', () => ({
transformSync: jest.fn(() => ({
code: '/* lwc-compiled */',
map: null,
warnings: [],
})),
}));

jest.mock('@babel/core', () => ({
transform: jest.fn(() => ({ code: '/* babel */' })),
}));

jest.mock('@lwc/template-compiler/dist/index.cjs', () => ({
generateScopeTokens: jest.fn(() => ({ cssScopeTokens: undefined })),
}));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jest.mock('@lwc/compiler/dist/index.cjs', () => ({
transformSync: jest.fn(() => ({
code: '/* lwc-compiled */',
map: null,
warnings: [],
})),
}));
jest.mock('@babel/core', () => ({
transform: jest.fn(() => ({ code: '/* babel */' })),
}));
jest.mock('@lwc/template-compiler/dist/index.cjs', () => ({
generateScopeTokens: jest.fn(() => ({ cssScopeTokens: undefined })),
}));

None of these are used in the string match helper.


const { extractNamespace } = require('../index');

describe('extractNamespace', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Are the filepaths always absolute or do we need tests for relative?
  2. Add tests for modules/x/foo/bar.js and modules/x/foo/bar/baz.js.

Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Comment on lines +8 to +14
}).toThrow(
expect.objectContaining({
message: expect.stringMatching(
/LWC1007:[\s\S]*Class private methods are not enabled/
),
})
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}).toThrow(
expect.objectContaining({
message: expect.stringMatching(
/LWC1007:[\s\S]*Class private methods are not enabled/
),
})
);
}).toThrow(/LWC1007:[\s\S]*Class private methods are not enabled/);
Suggested change
}).toThrow(
expect.objectContaining({
message: expect.stringMatching(
/LWC1007:[\s\S]*Class private methods are not enabled/
),
})
);
}).toThrowError(/LWC1007:[\s\S]*Class private methods are not enabled/);

One or the other is equivalent.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    TypeError: expect(...).toThrowError is not a function

so I went with the toThrow option

Comment thread packages/@lwc/jest-transformer/src/extract-namespace.js Outdated
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
Signed-off-by: a.chabot <a.chabot@salesforce.com>
@a-chabot a-chabot merged commit 84f9428 into salesforce:master Apr 15, 2026
6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants