Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Oct 23, 2023
1 parent 638ecb1 commit a1f34a2
Show file tree
Hide file tree
Showing 32 changed files with 1,157 additions and 1,278 deletions.
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const esModules = [
'@jupyterlab/',
'lib0',
'nanoid',
'nbdime',
'vscode-ws-jsonrpc',
'y-protocols',
'y-websocket',
Expand All @@ -30,6 +31,8 @@ module.exports = {
'<rootDir>/jupyter-config',
'<rootDir>/ui-tests'
],
reporters: ['default', 'github-actions'],
setupFiles: ['<rootDir>/testutils/jest-setup-files.js'],
testRegex: 'src/.*/.*.spec.ts[x]?$',
transformIgnorePatterns: [`/node_modules/(?!${esModules}).+`]
};
1 change: 1 addition & 0 deletions jupyterlab_git/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async def test_all_history_handler_localbranch(mock_git, jp_fetch, jp_root_dir):
mock_git.status.return_value = maybe_future(status)

# When
body = {"history_count": 25}
response = await jp_fetch(
NAMESPACE, local_path.name, "all_history", body=json.dumps(body), method="POST"
)
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@
"@babel/preset-env": "^7.0.0",
"@jupyterlab/builder": "^4.0.0",
"@jupyterlab/testutils": "^4.0.0",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/diff-match-patch": "^1.0.32",
"@types/enzyme": "^3.1.15",
"@types/jest": "^29.2.0",
"@types/json-schema": "^7.0.11",
"@types/react": "^18.0.26",
Expand All @@ -114,10 +116,8 @@
"@types/resize-observer-browser": "^0.1.7",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"all-contributors-cli": "^6.14.0",
"css-loader": "^6.7.1",
"enzyme": "^3.7.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
Expand All @@ -126,11 +126,11 @@
"husky": "^8.0.3",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.2.0",
"jest-fetch-mock": "^3.0.0",
"lint-staged": "^13.2.3",
"mkdirp": "^1.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.0",
"resize-observer-polyfill": "^1.5.1",
"rimraf": "^5.0.1",
"source-map-loader": "^1.0.2",
"style-loader": "^3.3.1",
Expand All @@ -139,7 +139,7 @@
"stylelint-config-standard": "^34.0.0",
"stylelint-csstree-validator": "^3.0.0",
"stylelint-prettier": "^4.0.0",
"ts-jest": "^26.0.0",
"ts-jest": "^29.1.0",
"typescript": "~5.0.2",
"yjs": "^13.5.40"
},
Expand Down
16 changes: 12 additions & 4 deletions src/__tests__/commands.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {
IMockedResponse,
mockedRequestAPI
} from './utils';
import {
CodeMirrorEditorFactory,
EditorLanguageRegistry
} from '@jupyterlab/codemirror';

jest.mock('../git');
jest.mock('@jupyterlab/apputils');
Expand Down Expand Up @@ -43,7 +47,7 @@ describe('git-commands', () => {
};

mockGit.requestAPI.mockImplementation(
mockedRequestAPI({ responses: mockResponses })
mockedRequestAPI({ responses: mockResponses }) as any
);

commands = new CommandRegistry();
Expand All @@ -56,8 +60,10 @@ describe('git-commands', () => {
addCommands(
app as JupyterFrontEnd,
model,
new CodeMirrorEditorFactory().newDocumentEditor,
new EditorLanguageRegistry(),
mockedFileBrowserModel,
null,
null as any,
nullTranslator
);
});
Expand All @@ -73,6 +79,7 @@ describe('git-commands', () => {
button: {
accept: true,
actions: [],
ariaLabel: '',
caption: '',
className: '',
displayType: 'default',
Expand All @@ -86,7 +93,7 @@ describe('git-commands', () => {
const spyReset = jest.spyOn(model, 'reset');
spyReset.mockResolvedValueOnce(undefined);
const spyCheckout = jest.spyOn(model, 'checkout');
spyCheckout.mockResolvedValueOnce(undefined);
spyCheckout.mockResolvedValueOnce({} as any);

const path = 'file/path.ext';
model.pathRepository = DEFAULT_REPOSITORY_PATH;
Expand Down Expand Up @@ -140,6 +147,7 @@ describe('git-commands', () => {
button: {
accept: true,
actions: [],
ariaLabel: '',
caption: '',
className: '',
displayType: 'default',
Expand Down Expand Up @@ -169,7 +177,7 @@ describe('git-commands', () => {
}
}
}
})
}) as any
);

const path = DEFAULT_REPOSITORY_PATH;
Expand Down
23 changes: 13 additions & 10 deletions src/__tests__/model.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
defaultMockedResponses,
DEFAULT_REPOSITORY_PATH,
IMockedResponses,
mockedRequestAPI
mockedRequestAPI,
IMockedResponse
} from './utils';

jest.mock('../git');
Expand All @@ -16,7 +17,7 @@ describe('IGitExtension', () => {
const mockGit = git as jest.Mocked<typeof git>;
let model: IGitExtension;
const docmanager = jest.mock('@jupyterlab/docmanager') as any;
let mockResponses: IMockedResponses;
let mockResponses: IMockedResponses & {responses: {[endpoint: string]: IMockedResponse}};

beforeEach(async () => {
jest.restoreAllMocks();
Expand All @@ -29,7 +30,9 @@ describe('IGitExtension', () => {
responses: { ...defaultMockedResponses }
};

mockGit.requestAPI.mockImplementation(mockedRequestAPI(mockResponses));
mockGit.requestAPI.mockImplementation(
mockedRequestAPI(mockResponses) as any
);

model = new GitExtension(docmanager as any, docregistry as any);
});
Expand Down Expand Up @@ -94,7 +97,7 @@ describe('IGitExtension', () => {
});

it('should emit repositoryChanged signal and request a refresh', async () => {
let path = DEFAULT_REPOSITORY_PATH;
let path: string | null = DEFAULT_REPOSITORY_PATH;

const testPathSignal = testEmission(model.repositoryChanged, {
test: (model, change) => {
Expand Down Expand Up @@ -198,7 +201,7 @@ describe('IGitExtension', () => {
describe('#status', () => {
it('should be clear if not in a git repository', async () => {
let status: Partial<Git.IStatusResult> = {
branch: null,
branch: undefined,
remote: null,
ahead: 0,
behind: 0,
Expand Down Expand Up @@ -254,9 +257,9 @@ describe('IGitExtension', () => {
const testSignal = testEmission(model.statusChanged, {
test: (model, receivedStatus) => {
expect(receivedStatus.branch).toEqual(branch);
expect(receivedStatus.files).toHaveLength(status.files.length);
expect(receivedStatus.files).toHaveLength(status.files?.length ?? 0);
expect(receivedStatus.files[0]).toMatchObject<Git.IStatusFileResult>({
...status.files[0]
...status.files![0]
});
}
});
Expand All @@ -280,7 +283,7 @@ describe('IGitExtension', () => {
['other_repo/file', null, 'repo'],
['root/other_repo/file', null, 'root/repo']
])(
'%s should return unmodified status with path relative to the repository',
'%s should return unmodified status with path %s to the repository %s',
async (path, expected, repo) => {
// Given
mockResponses.path = repo;
Expand All @@ -292,8 +295,8 @@ describe('IGitExtension', () => {
if (expected === null) {
expect(status).toBeNull();
} else {
expect(status.status).toEqual('unmodified');
expect(status.to).toEqual(expected);
expect(status!.status).toEqual('unmodified');
expect(status!.to).toEqual(expected);
}
}
);
Expand Down
16 changes: 9 additions & 7 deletions src/__tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ describe('plugin', () => {
}
} as unknown as jest.Mocked<IFileBrowserFactory>;
settingRegistry = new SettingRegistry({
connector: null
}) as jest.Mocked<SettingRegistry>;
connector: null as any
}) as any;
});

beforeEach(() => {
jest.resetAllMocks();
mockResponses = { responses: { ...defaultMockedResponses } };
mockGit.requestAPI.mockImplementation(mockedRequestAPI(mockResponses));
mockGit.requestAPI.mockImplementation(
mockedRequestAPI(mockResponses) as any
);
});

describe('#activate', () => {
it('should fail if no git is installed', async () => {
// Given
const endpoint = 'settings' + URLExt.objectToQueryString({ version });
mockResponses.responses[endpoint] = {
mockResponses.responses![endpoint] = {
body: request => {
return {
gitVersion: null,
Expand Down Expand Up @@ -85,7 +87,7 @@ describe('plugin', () => {
it('should fail if git version is < 2', async () => {
// Given
const endpoint = 'settings' + URLExt.objectToQueryString({ version });
mockResponses.responses[endpoint] = {
mockResponses.responses![endpoint] = {
body: request => {
return {
gitVersion: '1.8.7',
Expand Down Expand Up @@ -119,7 +121,7 @@ describe('plugin', () => {
it('should fail if server and extension version do not match', async () => {
// Given
const endpoint = 'settings' + URLExt.objectToQueryString({ version });
mockResponses.responses[endpoint] = {
mockResponses.responses![endpoint] = {
body: request => {
return {
gitVersion: '2.22.0',
Expand Down Expand Up @@ -156,7 +158,7 @@ describe('plugin', () => {
it('should fail if the server extension is not installed', async () => {
// Given
const endpoint = 'settings' + URLExt.objectToQueryString({ version });
mockResponses.responses[endpoint] = {
mockResponses.responses![endpoint] = {
status: 404
};
const mockedErrorMessage = showErrorMessage as jest.MockedFunction<
Expand Down
Loading

0 comments on commit a1f34a2

Please sign in to comment.