Skip to content

Commit

Permalink
Fix type errors and snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 committed Mar 29, 2019
1 parent 4a88f45 commit 930cbf3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-android-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -166,6 +167,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-futures-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -224,6 +226,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava-open"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -285,6 +288,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava/javadoc-link-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -391,6 +395,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava/src/com/google-open"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -455,6 +460,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava/src/com/google/common-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -514,6 +520,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava/src/com/google/thirdparty/publicsuffix-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -577,6 +584,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava-bom-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -636,6 +644,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava-gwt-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -695,6 +704,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava-testlib-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -754,6 +764,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-guava-tests-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -813,6 +824,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-refactorings-closed"
focusable="false"
height="16"
style={null}
Expand Down Expand Up @@ -872,6 +884,7 @@ exports[`render correctly 1`] = `
</svg>
<svg
className="euiIcon euiIcon--medium"
data-test-subj="codeFileTreeNode-Directory-Icon-util-closed"
focusable="false"
height="16"
style={null}
Expand Down
67 changes: 35 additions & 32 deletions x-pack/plugins/code/server/__tests__/git_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/* tslint:disable */

import Git from '@elastic/nodegit';
import assert from 'assert';
import { execSync } from 'child_process';
import fs from 'fs';
import * as mkdirp from 'mkdirp';
import os from 'os';
import path from 'path';
import rimraf from 'rimraf';
import { getDefaultBranch, GitOperations } from '../git_operations';
import * as mkdirp from "mkdirp";
import Git from '@elastic/nodegit';
import { createTestServerOption } from '../test_utils';

describe('git_operations', () => {
Expand Down Expand Up @@ -42,31 +42,36 @@ describe('git_operations', () => {
async function prepareProject(repoPath: string) {
mkdirp.sync(repoPath);
const repo = await Git.Repository.init(repoPath, 0);
const content = "";
fs.writeFileSync(path.join(repo.workdir(), "1"), content, 'utf8');
const content = '';
fs.writeFileSync(path.join(repo.workdir(), '1'), content, 'utf8');
const subFolder = 'src';
fs.mkdirSync(path.join(repo.workdir(), subFolder));
fs.writeFileSync(path.join(repo.workdir(), "src/2"), content, 'utf8');
fs.writeFileSync(path.join(repo.workdir(), "src/3"), content, 'utf8');
fs.writeFileSync(path.join(repo.workdir(), 'src/2'), content, 'utf8');
fs.writeFileSync(path.join(repo.workdir(), 'src/3'), content, 'utf8');

const index = await repo.refreshIndex();
await index.addByPath("1");
await index.addByPath("src/2");
await index.addByPath("src/3");
await index.addByPath('1');
await index.addByPath('src/2');
await index.addByPath('src/3');
index.write();
const treeId = await index.writeTree();
const committer = Git.Signature.create("tester",
"[email protected]", Date.now() / 1000, 60);
const commit = await repo.createCommit("HEAD", committer, committer, "commit for test", treeId, []);
const committer = Git.Signature.create('tester', '[email protected]', Date.now() / 1000, 60);
const commit = await repo.createCommit(
'HEAD',
committer,
committer,
'commit for test',
treeId,
[]
);
// tslint:disable-next-line:no-console
console.log(`created commit ${commit.tostrS()}`);
return repo;
}

// @ts-ignore
before(async () => {
await prepareProject(
path.join(serverOptions.repoPath, repoUri)
);
await prepareProject(path.join(serverOptions.repoPath, repoUri));
});
const repoUri = 'github.com/test/test_repo';

Expand All @@ -76,25 +81,23 @@ describe('git_operations', () => {
const g = new GitOperations(serverOptions.repoPath);
let count = 0;
const iterator = await g.iterateRepo(repoUri, 'HEAD');
for await (let value of iterator) {
if(count=== 0) {
assert.strictEqual("1", value.name);
assert.strictEqual("1",value.path)
} else if(count=== 1) {
assert.strictEqual("2", value.name);
assert.strictEqual("src/2",value.path)
} else if(count=== 2) {
assert.strictEqual("3", value.name);
assert.strictEqual("src/3",value.path)
for await (const value of iterator) {
if (count === 0) {
assert.strictEqual('1', value.name);
assert.strictEqual('1', value.path);
} else if (count === 1) {
assert.strictEqual('2', value.name);
assert.strictEqual('src/2', value.path);
} else if (count === 2) {
assert.strictEqual('3', value.name);
assert.strictEqual('src/3', value.path);
} else {
assert.fail("this repo should contains exactly 2 files")
assert.fail('this repo should contains exactly 2 files');
}
count++;
}
const totalFiles = await g.countRepoFiles(repoUri, 'HEAD');
assert.strictEqual(count, 3, "this repo should contains exactly 2 files");
assert.strictEqual(totalFiles, 3, "this repo should contains exactly 2 files");
})
assert.strictEqual(count, 3, 'this repo should contains exactly 2 files');
assert.strictEqual(totalFiles, 3, 'this repo should contains exactly 2 files');
});
});


2 changes: 2 additions & 0 deletions x-pack/plugins/code/server/__tests__/workspace_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ describe('workspace_handler tests', () => {
);
});

// @ts-ignore
before(() => {
mkdirp.sync(workspaceDir);
mkdirp.sync(repoDir);
});

// @ts-ignore
after(() => {
rimraf.sync(baseDir);
});
Expand Down

0 comments on commit 930cbf3

Please sign in to comment.