Skip to content

Commit a046b66

Browse files
authored
Switch to GitHub action for testing (jupyterlab#738)
* Switch to GitHub action for testing * Install python before using pip * Add python version in pip cache key * Correct unit test * Correct format error * Slight improvements to CI script
1 parent bf58cec commit a046b66

File tree

11 files changed

+341
-227
lines changed

11 files changed

+341
-227
lines changed

Diff for: .github/workflows/build.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: "*"
8+
9+
jobs:
10+
test-3x:
11+
name: Test Python ${{ matrix.python-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ['3.5', '3.6', '3.7', '3.8']
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Setup Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
architecture: 'x64'
25+
26+
- name: Get pip cache dir
27+
id: pip-cache
28+
run: |
29+
echo "::set-output name=dir::$(pip cache dir)"
30+
31+
- name: pip cache
32+
uses: actions/cache@v2
33+
with:
34+
path: ${{ steps.pip-cache.outputs.dir }}
35+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}
36+
restore-keys: |
37+
${{ runner.os }}-pip-${{ matrix.python-version }}-
38+
${{ runner.os }}-pip-
39+
40+
- name: Get yarn cache directory path
41+
id: yarn-cache-dir-path
42+
run: echo "::set-output name=dir::$(yarn cache dir)"
43+
- name: Setup yarn cache
44+
uses: actions/cache@v2
45+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
46+
env:
47+
# Increase this value to reset cache
48+
CACHE_NUMBER: 0
49+
with:
50+
path: |
51+
${{ steps.yarn-cache-dir-path.outputs.dir }}
52+
**/node_modules
53+
key: ${{ runner.os }}-yarn-${{ env.CACHE_NUMBER }}-${{ hashFiles('**/yarn.lock') }}
54+
restore-keys: |
55+
${{ runner.os }}-yarn-${{ env.CACHE_NUMBER }}
56+
${{ runner.os }}-yarn-
57+
58+
- name: Install dependencies
59+
run: |
60+
pip install wheel
61+
pip install --upgrade --upgrade-strategy=eager pytest pytest-asyncio "jupyterlab~=2.0"
62+
63+
- name: Test the extension
64+
run: |
65+
# Build the sdist (identical to what will be uploaded to eg pypi on release)
66+
python setup.py sdist
67+
# Linter checks
68+
jlpm run eslint-check
69+
70+
# Install the extension from the sdist ensuring the cache is unused
71+
pip install jupyterlab_git[test] --pre --no-index --find-links=dist --no-deps --no-cache-dir -v
72+
# Install the extension dependencies based on the current setup.py
73+
pip install jupyterlab_git[test]
74+
75+
# Run the Python tests
76+
pytest jupyterlab_git -r ap
77+
# Run the TS/JS tests
78+
jlpm run test
79+
80+
# Log the current state of jupyterlab's extensions
81+
jupyter labextension list
82+
# Rebuild jupyterlab to include our extension
83+
jupyter lab build
84+
# Run the standard jupyterlab browser integration test
85+
jupyter serverextension list 1>serverextensions 2>&1
86+
cat serverextensions | grep "jupyterlab_git.*OK"
87+
jupyter labextension list 1>labextensions 2>&1
88+
cat labextensions | grep "@jupyterlab/git.*OK"
89+
python -m jupyterlab.browser_check
90+
# Run our extension-specific browser integration test
91+
python tests/test-browser/run_browser_test.py

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,4 @@ node_modules/
123123
# vim stuff
124124
*.swp
125125
.devcontainer/
126+
src/version.ts

Diff for: .travis.yml

-37
This file was deleted.

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# jupyterlab-git
22

3-
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab/jupyterlab-git/master?urlpath=lab/tree/examples/demo.ipynb) [![Build Status](https://travis-ci.org/jupyterlab/jupyterlab-git.svg?branch=master)](https://travis-ci.org/jupyterlab/jupyterlab-git) [![Version](https://img.shields.io/npm/v/@jupyterlab/git.svg)](https://www.npmjs.com/package/@jupyterlab/git) [![Version](https://img.shields.io/pypi/v/jupyterlab-git.svg)](https://pypi.org/project/jupyterlab-git/) [![Downloads](https://img.shields.io/npm/dm/@jupyterlab/git.svg)](https://www.npmjs.com/package/@jupyterlab/git) [![Version](https://img.shields.io/conda/vn/conda-forge/jupyterlab-git.svg)](https://anaconda.org/conda-forge/jupyterlab-git) [![Downloads](https://img.shields.io/conda/dn/conda-forge/jupyterlab-git.svg)](https://anaconda.org/conda-forge/jupyterlab-git)<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
3+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab/jupyterlab-git/master?urlpath=lab/tree/examples/demo.ipynb) [![Github Actions Status](https://github.com/jupyterlab/jupyterlab-git/workflows/Test/badge.svg)](https://github.com/jupyterlab/jupyterlab-git/actions?query=workflow%3ATest) [![Version](https://img.shields.io/npm/v/@jupyterlab/git.svg)](https://www.npmjs.com/package/@jupyterlab/git) [![Version](https://img.shields.io/pypi/v/jupyterlab-git.svg)](https://pypi.org/project/jupyterlab-git/) [![Downloads](https://img.shields.io/npm/dm/@jupyterlab/git.svg)](https://www.npmjs.com/package/@jupyterlab/git) [![Version](https://img.shields.io/conda/vn/conda-forge/jupyterlab-git.svg)](https://anaconda.org/conda-forge/jupyterlab-git) [![Downloads](https://img.shields.io/conda/dn/conda-forge/jupyterlab-git.svg)](https://anaconda.org/conda-forge/jupyterlab-git)<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
44
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors-)
55
<!-- ALL-CONTRIBUTORS-BADGE:END -->
66

Diff for: package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,28 @@
8181
"@jupyterlab/testutils": "^2.0.0",
8282
"@types/codemirror": "^0.0.79",
8383
"@types/diff-match-patch": "^1.0.32",
84-
"@types/enzyme": "3.1.15",
84+
"@types/enzyme": "^3.1.15",
8585
"@types/jest": "^24",
8686
"@types/react": "~16.8.13",
8787
"@types/react-dom": "~16.0.5",
8888
"@types/react-textarea-autosize": "^4.3.5",
8989
"@typescript-eslint/eslint-plugin": "^2.25.0",
9090
"@typescript-eslint/parser": "^2.25.0",
91-
"all-contributors-cli": "6.14.0",
92-
"enzyme": "3.7.0",
93-
"enzyme-adapter-react-16": "1.7.0",
91+
"all-contributors-cli": "^6.14.0",
92+
"enzyme": "^3.7.0",
93+
"enzyme-adapter-react-16": "^1.7.0",
9494
"eslint": "^6.8.0",
9595
"eslint-config-prettier": "^6.10.1",
9696
"eslint-plugin-prettier": "^3.1.2",
9797
"eslint-plugin-react": "^7.19.0",
9898
"genversion": "^2.2.1",
99-
"husky": "1.3.1",
99+
"husky": "^1.3.1",
100100
"identity-obj-proxy": "^3.0.0",
101101
"jest": "^24",
102102
"jest-fetch-mock": "^1.6.6",
103-
"lint-staged": "8.1.5",
103+
"lint-staged": "^8.1.5",
104104
"mkdirp": "^1.0.3",
105-
"prettier": "1.16.4",
105+
"prettier": "^1.16.4",
106106
"puppeteer": "^1.10.0",
107107
"rimraf": "^2.6.1",
108108
"ts-jest": "^24",

Diff for: src/components/GitPanel.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
171171
refreshHistory = async () => {
172172
if (this.props.model.pathRepository !== null) {
173173
// Get git log for current branch
174-
const logData = await this.props.model.log(this.props.settings.composite[
175-
'historyCount'
176-
] as number);
174+
const logData = await this.props.model.log(
175+
this.props.settings.composite['historyCount'] as number
176+
);
177177
let pastCommits = new Array<Git.ISingleCommitInfo>();
178178
if (logData.code === 0) {
179179
pastCommits = logData.commits;

Diff for: src/components/SinglePastCommitInfo.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ export class SinglePastCommitInfo extends React.Component<
135135
log = await this.props.model.detailedLog(this.props.commit.commit);
136136
} catch (err) {
137137
console.error(
138-
`Error while getting detailed log for commit ${
139-
this.props.commit.commit
140-
} and path ${this.props.model.pathRepository}`,
138+
`Error while getting detailed log for commit ${this.props.commit.commit} and path ${this.props.model.pathRepository}`,
141139
err
142140
);
143141
this.setState({ loadingState: 'error' });

Diff for: src/model.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,9 @@ export class GitExtension implements IGitExtension {
465465

466466
if (response.ok) {
467467
if (body.checkout_branch) {
468-
const files = (await this.changedFiles(
469-
this._currentBranch.name,
470-
body.branchname
471-
))['files'];
468+
const files = (
469+
await this.changedFiles(this._currentBranch.name, body.branchname)
470+
)['files'];
472471
if (files) {
473472
files.forEach(file => this._revertFile(file));
474473
}

Diff for: tests/test-components/NBDiff.spec.tsx

+43-25
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ describe('NBDiff', () => {
2222
}
2323
};
2424

25-
const jsonResult: Promise<any> = Promise.resolve({
26-
message: 'TEST_ERROR_MESSAGE'
25+
let resolveJson: (value?: any) => void;
26+
const jsonResult = new Promise<any>(resolve => {
27+
resolveJson = resolve;
2728
});
2829

2930
(httpGitRequest as jest.Mock).mockReturnValue(
@@ -32,20 +33,29 @@ describe('NBDiff', () => {
3233

3334
// When
3435
const node = shallow<NBDiff>(<NBDiff {...props} />);
36+
resolveJson({
37+
message: 'TEST_ERROR_MESSAGE'
38+
});
3539

3640
// Then
37-
await jsonResult;
38-
node.update();
39-
40-
expect(httpGitRequest).toHaveBeenCalled();
41-
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
42-
file_path: 'top/repo/path/path/to/File.ipynb',
43-
ref_remote: { special: 'WORKING' },
44-
ref_local: { git: '83baee' }
41+
let resolveTest: () => void;
42+
const terminateTest = new Promise(resolve => {resolveTest = resolve});
43+
setImmediate(() => {
44+
expect(httpGitRequest).toHaveBeenCalled();
45+
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
46+
file_path: 'top/repo/path/path/to/File.ipynb',
47+
ref_remote: { special: 'WORKING' },
48+
ref_local: { git: '83baee' }
49+
});
50+
expect(
51+
node
52+
.update()
53+
.find('.jp-git-diff-error')
54+
.text()
55+
).toContain('TEST_ERROR_MESSAGE');
56+
resolveTest();
4557
});
46-
expect(node.find('.jp-git-diff-error').text()).toContain(
47-
'TEST_ERROR_MESSAGE'
48-
);
58+
await terminateTest;
4959
});
5060

5161
it('should render header and cell diff components in success case', async () => {
@@ -59,27 +69,35 @@ describe('NBDiff', () => {
5969
}
6070
};
6171

62-
const jsonResult: Promise<any> = Promise.resolve(diffResponse);
72+
let resolveJson: (value?: any) => void;
73+
const jsonResult: Promise<any> = new Promise<any>(resolve => {
74+
resolveJson = resolve;
75+
});
6376

6477
(httpGitRequest as jest.Mock).mockReturnValue(
6578
createTestResponse(200, jsonResult)
6679
);
6780

6881
// When
6982
const node = shallow<NBDiff>(<NBDiff {...props} />);
83+
resolveJson(diffResponse);
7084

7185
// Then
72-
await jsonResult;
73-
node.update();
74-
75-
expect(httpGitRequest).toHaveBeenCalled();
76-
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
77-
file_path: 'top/repo/path/path/to/File.ipynb',
78-
ref_remote: { special: 'WORKING' },
79-
ref_local: { git: '83baee' }
86+
let resolveTest: () => void;
87+
const terminateTest = new Promise(resolve => {resolveTest = resolve});
88+
setImmediate(() => {
89+
expect(httpGitRequest).toHaveBeenCalled();
90+
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
91+
file_path: 'top/repo/path/path/to/File.ipynb',
92+
ref_remote: { special: 'WORKING' },
93+
ref_local: { git: '83baee' }
94+
});
95+
node.update();
96+
expect(node.find('.jp-git-diff-error')).toHaveLength(0);
97+
expect(node.find(NBDiffHeader)).toHaveLength(1);
98+
expect(node.find(CellDiff)).toHaveLength(3);
99+
resolveTest();
80100
});
81-
expect(node.find('.jp-git-diff-error')).toHaveLength(0);
82-
expect(node.find(NBDiffHeader)).toHaveLength(1);
83-
expect(node.find(CellDiff)).toHaveLength(3);
101+
await terminateTest;
84102
});
85103
});

0 commit comments

Comments
 (0)