basic test setup

pull/4791/head
Your Name 6 months ago
parent 9da8d51f93
commit 5781a0cae4
  1. 3
      apps/remix-ide-e2e/src/githttpbackend/package.json
  2. 48
      apps/remix-ide-e2e/src/githttpbackend/server.ts
  3. 38
      apps/remix-ide-e2e/src/githttpbackend/server2.js
  4. 10
      apps/remix-ide-e2e/src/githttpbackend/setup.sh
  5. 54
      apps/remix-ide-e2e/src/tests/dgit_local.test.ts
  6. 47
      apps/remix-ide/src/app/files/dgitProvider.ts
  7. 4
      libs/remix-ui/git/src/components/buttons/commitmessage.tsx
  8. 2
      libs/remix-ui/git/src/components/panels/clone.tsx
  9. 6
      libs/remix-ui/git/src/lib/gitactions.ts

@ -1,4 +1,7 @@
{
"scripts": {
"start:server": "npx ts-node server.ts"
},
"dependencies": {
"body-parser": "^1.20.2",
"child_process": "^1.0.2",

@ -0,0 +1,48 @@
import * as http from 'http';
import { spawn } from 'child_process';
import * as path from 'path';
let backend = require('git-http-backend');
import * as zlib from 'zlib';
const directory = process.argv[2];
if (!directory) {
console.error('Please provide a directory as a command line argument.');
process.exit(1);
}
const server = http.createServer((req, res) => {
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', 'true');
if (req.method === 'OPTIONS') {
// Handle preflight request
res.writeHead(204);
res.end();
return;
}
const repo = req.url?.split('/')[1];
const dir = path.join(directory, 'git', repo || '');
console.log(dir);
const reqStream = req.headers['content-encoding'] === 'gzip' ? req.pipe(zlib.createGunzip()) : req;
reqStream.pipe(backend(req.url || '', (err, service) => {
if (err) return res.end(err + '\n');
res.setHeader('content-type', service.type);
console.log(service.action, repo, service.fields);
const ps = spawn(service.cmd, [...service.args, dir]);
ps.stdout.pipe(service.createStream()).pipe(ps.stdin);
})).pipe(res);
});
server.listen(6868, () => {
console.log('Server is listening on port 6868');
});

@ -1,38 +0,0 @@
var http = require('http');
var spawn = require('child_process').spawn;
var path = require('path');
var backend = require('git-http-backend');
var zlib = require('zlib');
var server = http.createServer(function (req, res) {
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
if (req.method === 'OPTIONS') {
// Handle preflight request
res.writeHead(204);
res.end();
return;
}
var repo = req.url.split('/')[1];
var dir = path.join('/home/bunsen/', 'git', repo);
console.log(dir);
var reqStream = req.headers['content-encoding'] == 'gzip' ? req.pipe(zlib.createGunzip()) : req;
reqStream.pipe(backend(req.url, function (err, service) {
if (err) return res.end(err + '\n');
res.setHeader('content-type', service.type);
console.log(service.action, repo, service.fields);
var ps = spawn(service.cmd, service.args.concat(dir));
ps.stdout.pipe(service.createStream()).pipe(ps.stdin);
})).pipe(res);
});
server.listen(3000);

@ -0,0 +1,10 @@
cd /tmp/
rm -rf git/bare.git
rm -rf git
mkdir -p git
cd git
mkdir bare.git
cd bare.git
git init --bare
cd /tmp/

@ -0,0 +1,54 @@
import { ChildProcess, spawn } from "child_process"
import kill from 'tree-kill'
import init from "../helpers/init"
let gitserver: ChildProcess
module.exports = {
'@disabled': true,
before: function (browser, done) {
init(browser, done)
},
after: function (browser) {
browser.perform((done) => {
console.log('kill server', gitserver.pid)
kill(gitserver.pid)
done()
})
},
'run server #group1': function (browser) {
browser.perform(async (done) => {
gitserver = await spawnGitServer('/tmp/')
console.log('working directory', process.cwd())
done()
})
},
'clone a repository': function (browser) {
console.log('cloning')
}
}
async function spawnGitServer(path: string): Promise<ChildProcess> {
console.log(process.cwd())
try {
const server = spawn('yarn && npx ts-node server.ts', [`${path}`], { cwd: process.cwd() + '/apps/remix-ide-e2e/src/githttpbackend/', shell: true, detached: true })
console.log('spawned', server.stdout.closed, server.stderr.closed)
return new Promise((resolve, reject) => {
server.stdout.on('data', function (data) {
console.log(data.toString())
if (
data.toString().includes('is listening')
|| data.toString().includes('address already in use')
) {
console.log('resolving')
resolve(server)
}
})
server.stderr.on('err', function (data) {
console.log(data.toString())
reject(data.toString())
})
})
} catch (e) {
console.log(e)
}
}

@ -87,8 +87,9 @@ class DGitProvider extends Plugin {
async addIsomorphicGitConfig(input) {
const token = await this.call('config' as any, 'getAppParameter', 'settings/gist-access-token')
return {
//corsProxy: 'http://192.168.1.7:39049',
let config = {
corsProxy: null,
http,
onAuth: url => {
url
@ -99,6 +100,27 @@ class DGitProvider extends Plugin {
return auth
}
}
if(input.url) {
const url = new URL(input.url)
if (url.hostname.includes('github.com')) {
config = {
...config,
corsProxy: 'https://corsproxy.remixproject.org/',
}
}
}
if((input.remote && input.remote.url)) {
const url = new URL(input.remote.url)
if (url.hostname.includes('github.com')) {
config = {
...config,
corsProxy: 'https://corsproxy.remixproject.org/',
}
}
}
return config
}
async getCommandUser(input) {
@ -117,9 +139,9 @@ class DGitProvider extends Plugin {
author.name = username
author.email = email
} else if (token) {
console.log('token', token)
const gitHubUser = await this.getGitHubUser({ token })
console.log('gitHubUser', gitHubUser)
if (gitHubUser) {
author.name = gitHubUser.user.login
}
@ -300,14 +322,11 @@ class DGitProvider extends Plugin {
}
async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> {
//console.log(commitHash1, commitHash2, [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })])
const result: commitChange[] = await git.walk({
...await this.addIsomorphicGitConfigFS(),
trees: [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })],
map: async function (filepath, [A, B]) {
// ignore directories
//console.log(filepath, A, B)
if (filepath === '.') {
return
@ -330,7 +349,6 @@ class DGitProvider extends Plugin {
path: filepath,
}
//console.log('Aoid', Aoid, 'Boid', Boid, commitChange)
// determine modification type
if (Aoid !== Boid) {
@ -351,7 +369,7 @@ class DGitProvider extends Plugin {
return undefined
},
})
//console.log(result)
return result
}
@ -591,7 +609,7 @@ class DGitProvider extends Plugin {
...await this.addIsomorphicGitConfig(input),
...await this.addIsomorphicGitConfigFS()
}
console.log(cmd)
this.call('terminal', 'logHtml', `Cloning ${input.url}...`)
const result = await git.clone(cmd)
if (!input.workspaceExists) {
@ -737,7 +755,7 @@ class DGitProvider extends Plugin {
}
async push(input: pushInputType) {
console.log('push input', input)
const cmd = {
force: input.force,
ref: input.ref.name,
@ -754,18 +772,19 @@ class DGitProvider extends Plugin {
...cmd,
...await this.addIsomorphicGitConfig(input),
}
console.log('push cmd', cmd2)
const result = await git.push({
...await this.addIsomorphicGitConfigFS(),
...cmd2
})
console.log('push result', cmd2, result)
return result
}
}
async pull(input: pullInputType) {
const cmd = {
ref: input.ref.name,
remoteRef: input.remoteRef && input.remoteRef.name,
@ -986,7 +1005,7 @@ class DGitProvider extends Plugin {
// OCTOKIT FEATURES
async remotebranches(input: { owner: string, repo: string, token: string, page: number, per_page: number }) {
console.log(input)
const octokit = new Octokit({
auth: input.token

@ -45,6 +45,10 @@ export const CommitMessage = () => {
remote: getRemote(),
ref: context.currentBranch
})
await actions.pull({
remote: getRemote(),
ref: context.currentBranch
})
}
const commitNotAllowed = () => {

@ -69,7 +69,7 @@ export const Clone = () => {
</InputGroup>
<input name='clonebranch' onChange={e => onCloneBranchChange(e.target.value)} value={cloneBranch} className="form-control mb-1 mt-2" placeholder="branch" type="text" id="clonebranch" />
<GitUIButton disabledCondition={!cloneUrl || !cloneBranch} data-id='clonebtn' className='btn btn-primary mt-1 w-100' onClick={async () => {
<GitUIButton disabledCondition={!cloneUrl} data-id='clonebtn' className='btn btn-primary mt-1 w-100' onClick={async () => {
clone()
}}>clone</GitUIButton>
<hr />

@ -299,6 +299,7 @@ export const clone = async (input: cloneInputType) => {
const repoName = lastPart.split(".")[0];
const timestamp = new Date().getTime();
const repoNameWithTimestamp = `${repoName}-${timestamp}`;
try {
await disableCallBacks()
const token = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/gist-access-token')
@ -310,9 +311,8 @@ export const clone = async (input: cloneInputType) => {
type: 'success',
message: `Cloned ${input.url} to ${repoNameWithTimestamp}`
})
//}
} catch (e: any) {
//await plugin.call('filePanel', 'deleteWorkspace', repoNameWithTimestamp)
await parseError(e)
}
dispatch(setLoading(false))
@ -342,6 +342,7 @@ export const pull = async (input: pullInputType) => {
await plugin.call('dgitApi', 'pull', input)
await gitlog()
} catch (e: any) {
console.log(e)
await parseError(e)
}
dispatch(setLoading(false))
@ -354,6 +355,7 @@ export const push = async (input: pushInputType) => {
try {
await plugin.call('dgitApi', 'push', input)
} catch (e: any) {
console.log(e)
await parseError(e)
}
dispatch(setLoading(false))

Loading…
Cancel
Save