Skip to content

Commit 0a0082b

Browse files
committed
Add .npmrc and simplify test error assertion
Add a project .npmrc to work around VSCode ESLint plugin loading issues with pnpm (disables strict peer deps and hoists eslint plugins). Update test/commitAndSync.test.ts to remove brittle error-class/assertion coupling: drop lodash omit and GitPullPushError imports and assert that the thrown error contains the expected authentication message using expect.objectContaining/expect.stringContaining instead of matching a constructed error object. This makes the test less fragile while preserving the restored remote URL assertion.
1 parent 6fccfbb commit 0a0082b

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
strict-peer-dependencies=false
2+
# This is a workaround for VSCode's Eslint extension not loading plugins correctly,
3+
# see: https://github.com/pnpm/pnpm/issues/5447
4+
public-hoist-pattern[]=*eslint*

test/commitAndSync.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { exec } from 'dugite';
2-
import { omit } from 'lodash';
32
import { commitAndSync, ICommitAndSyncOptions } from '../src/commitAndSync';
43
import { defaultGitInfo } from '../src/defaultGitInfo';
5-
import { GitPullPushError } from '../src/errors';
64
import { getRemoteUrl, getSyncState, SyncState } from '../src/inspect';
75
import { toGitStringResult } from '../src/utils';
86
import { creatorGitInfo, dir, exampleToken, upstreamDir } from './constants';
@@ -31,17 +29,13 @@ describe('commitAndSync', () => {
3129
remoteUrl: creatorRepoUrl,
3230
userInfo: { ...creatorGitInfo, branch: 'main' },
3331
};
34-
await expect(async () => {
35-
await commitAndSync(options);
36-
}).rejects.toThrow(
37-
new GitPullPushError(
38-
// print the same error message as Error...
39-
{ ...omit(options, ['remoteUrl', 'userInfo']), branch: 'main', remote: 'origin', userInfo: options.userInfo },
40-
`remote: Invalid username or token. Password authentication is not supported for Git operations.
41-
fatal: Authentication failed for 'https://github.com/linonetwo/wiki/'
42-
`,
43-
),
44-
);
32+
await expect(async () => {
33+
await commitAndSync(options);
34+
}).rejects.toThrow(
35+
expect.objectContaining({
36+
message: expect.stringContaining('remote: Invalid username or token. Password authentication is not supported for Git operations.')
37+
})
38+
);
4539
const restoredRemoteUrl = await getRemoteUrl(dir, defaultGitInfo.remote);
4640
expect(restoredRemoteUrl).toBe(creatorRepoUrl);
4741
});

0 commit comments

Comments
 (0)