Skip to content

Commit

Permalink
[test] ensure that tmp dir is used for user data
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Jul 20, 2020
1 parent f9bd232 commit e02ac48
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"puppeteer": "^2.0.0",
"puppeteer-to-istanbul": "^1.2.2",
"tar": "^4.0.0",
"temp": "^0.9.1",
"unzip-stream": "^0.3.0",
"yargs": "^11.1.0"
},
Expand Down
4 changes: 4 additions & 0 deletions dev-packages/cli/src/theia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import * as temp from 'temp';
import * as yargs from 'yargs';
import { ApplicationPackageManager, rebuild } from '@theia/application-manager';
import { ApplicationProps } from '@theia/application-package';
Expand Down Expand Up @@ -216,6 +217,9 @@ function rebuildCommand(command: string, target: ApplicationProps.Target): yargs
testCoverage: boolean
}) => {
try {
if (!process.env.THEIA_CONFIG_DIR) {
process.env.THEIA_CONFIG_DIR = temp.track().mkdirSync('theia-test-config-dir');
}
await runTest({
start: async () => new Promise((resolve, reject) => {
const serverArgs = commandArgs('test').filter(a => a.indexOf('--test-') !== 0);
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/node/env-variables/env-variables-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import { FileUri } from '../file-uri';
export class EnvVariablesServerImpl implements EnvVariablesServer {

protected readonly envs: { [key: string]: EnvVariable } = {};
protected readonly configDirUri = FileUri.create(join(homedir(), '.theia')).toString();
protected readonly configDirUri: Promise<string>;

constructor() {
this.configDirUri = this.createConfigDirUri();
this.configDirUri.then(configDirUri => console.log(`Configuration directory URI: '${configDirUri}'`));
const prEnv = process.env;
Object.keys(prEnv).forEach((key: string) => {
let keyName = key;
Expand All @@ -38,6 +40,10 @@ export class EnvVariablesServerImpl implements EnvVariablesServer {
});
}

protected async createConfigDirUri(): Promise<string> {
return FileUri.create(process.env.THEIA_CONFIG_DIR || join(homedir(), '.theia')).toString();
}

async getExecPath(): Promise<string> {
return process.execPath;
}
Expand All @@ -53,7 +59,7 @@ export class EnvVariablesServerImpl implements EnvVariablesServer {
return this.envs[key];
}

async getConfigDirUri(): Promise<string> {
getConfigDirUri(): Promise<string> {
return this.configDirUri;
}

Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12502,6 +12502,13 @@ temp@^0.8.1, temp@^0.8.3:
dependencies:
rimraf "~2.6.2"

temp@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.9.1.tgz#2d666114fafa26966cd4065996d7ceedd4dd4697"
integrity sha512-WMuOgiua1xb5R56lE0eH6ivpVmg/lq2OHm4+LtT/xtEtPQ+sz6N3bBM6WZ5FvO1lO4IKIOb43qnhoc4qxP5OeA==
dependencies:
rimraf "~2.6.2"

tempfile@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/tempfile/-/tempfile-1.1.1.tgz#5bcc4eaecc4ab2c707d8bc11d99ccc9a2cb287f2"
Expand Down

0 comments on commit e02ac48

Please sign in to comment.