Skip to content

Commit 9da0f47

Browse files
committed
offline smoketests
1 parent 86fe750 commit 9da0f47

1 file changed

Lines changed: 70 additions & 43 deletions

File tree

test/smoke/src/main.ts

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const opts = minimist(args, {
3838
'build',
3939
'stable-build',
4040
'log',
41-
'wait-time'
41+
'wait-time',
42+
'test-repo',
43+
'keybindings'
4244
]
4345
});
4446

@@ -147,54 +149,79 @@ function toUri(path: string): string {
147149
return `${path}`;
148150
}
149151

150-
async function setup(): Promise<void> {
151-
console.log('*** Test data:', testDataPath);
152-
console.log('*** Preparing smoketest setup...');
153-
154-
const keybindingsUrl = `https://raw.githubusercontent.com/Microsoft/vscode-docs/master/build/keybindings/doc.keybindings.${getKeybindingPlatform()}.json`;
155-
console.log('*** Fetching keybindings...');
156-
157-
await new Promise((c, e) => {
158-
https.get(keybindingsUrl, res => {
159-
const output = fs.createWriteStream(keybindingsPath);
160-
res.on('error', e);
161-
output.on('error', e);
162-
output.on('close', c);
163-
res.pipe(output);
164-
}).on('error', e);
165-
});
152+
async function getKeybindings(): Promise<void> {
153+
if (opts.keybindings) {
154+
console.log('*** Using keybindings: ', opts.keybindings);
155+
const rawKeybindings = fs.readFileSync(opts.keybindings);
156+
fs.writeFileSync(keybindingsPath, rawKeybindings);
157+
} else {
158+
const keybindingsUrl = `https://raw.githubusercontent.com/Microsoft/vscode-docs/master/build/keybindings/doc.keybindings.${getKeybindingPlatform()}.json`;
159+
console.log('*** Fetching keybindings...');
160+
161+
await new Promise((c, e) => {
162+
https.get(keybindingsUrl, res => {
163+
const output = fs.createWriteStream(keybindingsPath);
164+
res.on('error', e);
165+
output.on('error', e);
166+
output.on('close', c);
167+
res.pipe(output);
168+
}).on('error', e);
169+
});
170+
}
171+
}
166172

167-
if (!fs.existsSync(workspaceFilePath)) {
168-
console.log('*** Creating workspace file...');
169-
const workspace = {
170-
folders: [
171-
{
172-
path: toUri(path.join(workspacePath, 'public'))
173-
},
174-
{
175-
path: toUri(path.join(workspacePath, 'routes'))
176-
},
177-
{
178-
path: toUri(path.join(workspacePath, 'views'))
179-
}
180-
]
181-
};
182-
183-
fs.writeFileSync(workspaceFilePath, JSON.stringify(workspace, null, '\t'));
173+
async function createWorkspaceFile(): Promise<void> {
174+
if (fs.existsSync(workspaceFilePath)) {
175+
return;
184176
}
185177

186-
if (!fs.existsSync(workspacePath)) {
187-
console.log('*** Cloning test project repository...');
188-
cp.spawnSync('git', ['clone', testRepoUrl, workspacePath]);
178+
console.log('*** Creating workspace file...');
179+
const workspace = {
180+
folders: [
181+
{
182+
path: toUri(path.join(workspacePath, 'public'))
183+
},
184+
{
185+
path: toUri(path.join(workspacePath, 'routes'))
186+
},
187+
{
188+
path: toUri(path.join(workspacePath, 'views'))
189+
}
190+
]
191+
};
192+
193+
fs.writeFileSync(workspaceFilePath, JSON.stringify(workspace, null, '\t'));
194+
}
195+
196+
async function setupRepository(): Promise<void> {
197+
if (opts['test-repo']) {
198+
console.log('*** Copying test project repository:', opts['test-repo']);
199+
rimraf.sync(workspacePath);
200+
// not platform friendly
201+
cp.execSync(`cp -R "${opts['test-repo']}" "${workspacePath}"`);
189202
} else {
190-
console.log('*** Cleaning test project repository...');
191-
cp.spawnSync('git', ['fetch'], { cwd: workspacePath });
192-
cp.spawnSync('git', ['reset', '--hard', 'FETCH_HEAD'], { cwd: workspacePath });
193-
cp.spawnSync('git', ['clean', '-xdf'], { cwd: workspacePath });
203+
if (!fs.existsSync(workspacePath)) {
204+
console.log('*** Cloning test project repository...');
205+
cp.spawnSync('git', ['clone', testRepoUrl, workspacePath]);
206+
} else {
207+
console.log('*** Cleaning test project repository...');
208+
cp.spawnSync('git', ['fetch'], { cwd: workspacePath });
209+
cp.spawnSync('git', ['reset', '--hard', 'FETCH_HEAD'], { cwd: workspacePath });
210+
cp.spawnSync('git', ['clean', '-xdf'], { cwd: workspacePath });
211+
}
212+
213+
console.log('*** Running npm install...');
214+
cp.execSync('npm install', { cwd: workspacePath, stdio: 'inherit' });
194215
}
216+
}
217+
218+
async function setup(): Promise<void> {
219+
console.log('*** Test data:', testDataPath);
220+
console.log('*** Preparing smoketest setup...');
195221

196-
console.log('*** Running npm install...');
197-
cp.execSync('npm install', { cwd: workspacePath, stdio: 'inherit' });
222+
await getKeybindings();
223+
await createWorkspaceFile();
224+
await setupRepository();
198225

199226
console.log('*** Smoketest setup done!\n');
200227
}

0 commit comments

Comments
 (0)