Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/template-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: 🔧 Install - Test Project
run: npm install --workspace=extester-test

- name: 🔧 Install RU langauge pack
run: code --install-extension ms-ceintl.vscode-language-pack-ru

- name: 🔍 Run Tests (macOS, windows)
if: ${{ ! startsWith(matrix.os, 'ubuntu') }}
run: npm test
Expand Down
24 changes: 22 additions & 2 deletions packages/extester/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class VSBrowser {
private codeVersion: string;
private releaseType: ReleaseQuality;
private logLevel: logging.Level;
private locale: string;
private static _instance: VSBrowser;
private readonly _startTimestamp: string;

Expand All @@ -43,13 +44,20 @@ export class VSBrowser {
return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}T${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
}

constructor(codeVersion: string, releaseType: ReleaseQuality, customSettings: object = {}, logLevel: logging.Level = logging.Level.INFO) {
constructor(
codeVersion: string,
releaseType: ReleaseQuality,
customSettings: object = {},
logLevel: logging.Level = logging.Level.INFO,
locale: string = '',
) {
this.storagePath = process.env.TEST_RESOURCES ? process.env.TEST_RESOURCES : path.resolve(DEFAULT_STORAGE_FOLDER);
this.extensionsFolder = process.env.EXTENSIONS_FOLDER ? process.env.EXTENSIONS_FOLDER : undefined;
this.customSettings = customSettings;
this.codeVersion = codeVersion;
this.releaseType = releaseType;
this.logLevel = logLevel;
this.locale = locale;
this._startTimestamp = this.formatTimestamp(new Date());

VSBrowser._instance = this;
Expand Down Expand Up @@ -87,7 +95,12 @@ export class VSBrowser {
fs.writeJSONSync(path.join(userSettings, 'settings.json'), defaultSettings);
console.log(`Writing code settings to ${path.join(userSettings, 'settings.json')}`);

const args = ['--no-sandbox', '--disable-dev-shm-usage', `--user-data-dir=${path.join(this.storagePath, 'settings')}`];
const args = ['--no-sandbox', '--disable-dev-shm-usage', `--user-data-dir=${path.join(this.storagePath, 'settings')}`]; // sem pridam locale

if (this.locale) {
console.log('locale is in args with value ' + this.locale);
args.push(`--locale ${this.locale}`);
}

if (this.extensionsFolder) {
args.push(`--extensions-dir=${this.extensionsFolder}`);
Expand All @@ -102,10 +115,14 @@ export class VSBrowser {
args.push(`--extensionDevelopmentPath=${process.env.EXTENSION_DEV_PATH}`);
}

console.log('args', args);

let options = new Options().setChromeBinaryPath(codePath).addArguments(...args) as any;
options['options_'].windowTypes = ['webview'];
options = options as Options;

console.log('options', options);

const prefs = new logging.Preferences();
prefs.setLevel(logging.Type.DRIVER, this.logLevel);
options.setLoggingPrefs(prefs);
Expand All @@ -117,6 +134,9 @@ export class VSBrowser {
}

console.log('Launching browser...');
// Print the full launch command for debugging
console.log('Launching VS Code with command:', `"${codePath}" ${args.join(' ')}`);

this._driver = await new Builder()
.setChromeService(new ServiceBuilder(chromeDriverBinaryPath))
.forBrowser(Browser.CHROME)
Expand Down
4 changes: 4 additions & 0 deletions packages/extester/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ program
.option('-f, --offline', 'Attempt to run without internet connection, make sure to have all requirements downloaded', false)
.option('-C, --coverage', 'Enable code coverage using c8')
.option('-r, --open_resource <resources...>', 'Open resources in VS Code. Multiple files and folders can be specified.')
.option('-L, --locale <locale>', 'to be defined')
.action(
withErrors(async (testFiles, cmd) => {
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir, cmd.coverage);
Expand All @@ -140,6 +141,7 @@ program
logLevel: cmd.log_level,
offline: cmd.offline,
resources: cmd.open_resource ?? [],
locale: cmd.locale,
});
}),
);
Expand All @@ -161,6 +163,7 @@ program
.option('-C, --coverage', 'Enable code coverage using c8')
.option('-r, --open_resource <resources...>', 'Open resources in VS Code. Multiple files and folders can be specified.')
.option('-n, --no_cache', 'Skip using cached version and download fresh copy without caching it', false)
.option('-L, --locale <locale>', 'to be defined22')
.action(
withErrors(async (testFiles, cmd) => {
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir, cmd.coverage);
Expand All @@ -178,6 +181,7 @@ program
config: cmd.mocha_config,
logLevel: cmd.log_level,
resources: cmd.open_resource ?? [],
locale: cmd.locale,
},
);
}),
Expand Down
7 changes: 7 additions & 0 deletions packages/extester/src/extester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ export class ExTester {
setupOptions: Omit<SetupOptions, 'vscodeVersion'> = DEFAULT_SETUP_OPTIONS,
runOptions: Omit<RunOptions, 'vscodeVersion'> = DEFAULT_RUN_OPTIONS,
): Promise<number> {
console.log('setupAndRunTests');
console.log('setup options:', JSON.stringify(setupOptions, null, 2));
console.log('run options:', JSON.stringify(runOptions, null, 2));

await this.setupRequirements({ ...setupOptions, vscodeVersion }, runOptions.offline, runOptions.cleanup);
return await this.runTests(testFilesPattern, {
...runOptions,
Expand All @@ -247,6 +251,9 @@ export class ExTester {
* @returns Promise resolving to the mocha process exit code - 0 for no failures, 1 otherwise
*/
async runTests(testFilesPattern: string | string[], runOptions: RunOptions = DEFAULT_RUN_OPTIONS): Promise<number> {
console.log('runTests');
console.log('run options:', JSON.stringify(runOptions, null, 2));

runOptions.vscodeVersion = loadCodeVersion(runOptions.vscodeVersion);
const patterns = typeof testFilesPattern === 'string' ? [testFilesPattern] : testFilesPattern;
return await this.code.runTests(patterns, runOptions);
Expand Down
16 changes: 13 additions & 3 deletions packages/extester/src/suite/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ export class VSRunner {
private cleanup: boolean;
private tmpLink = path.join(os.tmpdir(), 'extest-code');
private releaseType: ReleaseQuality;

constructor(bin: string, codeVersion: string, customSettings: object = {}, cleanup: boolean = false, releaseType: ReleaseQuality, config?: string) {
private locale: string | undefined;

constructor(
bin: string,
codeVersion: string,
customSettings: object = {},
cleanup: boolean = false,
releaseType: ReleaseQuality,
config?: string,
locale?: string,
) {
const conf = this.loadConfig(config);
this.mocha = new Mocha(conf);
this.chromeBin = bin;
this.customSettings = customSettings;
this.codeVersion = codeVersion;
this.cleanup = cleanup;
this.releaseType = releaseType;
this.locale = locale;
}

/**
Expand All @@ -58,7 +68,7 @@ export class VSRunner {
runTests(testFilesPattern: string[], code: CodeUtil, logLevel: logging.Level = logging.Level.INFO, resources: string[]): Promise<number> {
return new Promise((resolve) => {
const self = this;
const browser: VSBrowser = new VSBrowser(this.codeVersion, this.releaseType, this.customSettings, logLevel);
const browser: VSBrowser = new VSBrowser(this.codeVersion, this.releaseType, this.customSettings, logLevel, this.locale);
let coverage: Coverage | undefined;

const testFiles = new Set<string>();
Expand Down
5 changes: 4 additions & 1 deletion packages/extester/src/util/codeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface RunOptions {
offline?: boolean;
/** list of resources to be opened by VS Code */
resources: string[];
/** tbd */
locale?: string;
}

/** defaults for the [[RunOptions]] */
Expand All @@ -55,7 +57,7 @@ export const DEFAULT_RUN_OPTIONS = {
logLevel: logging.Level.INFO,
offline: false,
resources: [],
noCache: false,
noCache: false, //???
};

/**
Expand Down Expand Up @@ -321,6 +323,7 @@ export class CodeUtil {
runOptions.cleanup,
this.releaseType,
runOptions.config,
runOptions.locale,
);
return await runner.runTests(testFilesPattern, this, runOptions.logLevel, runOptions.resources);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
"compile": "tsc -p ./ && npm run lint",
"lint": "eslint --fix --fix-type layout src",
"cb-init": "echo hello_ExTester | clipboard",
"ui-test": "npm run cb-init && extest setup-and-run './out/test/cli/order-3.test.js' './out/test/cli/order-2.test.js' './out/test/cli/order-1.test.js' './out/test/**/!(clipboard)*.test.js' './out/test/system/clipboard.test.js' -u -i -r . -e ./test-extensions",
"ui-test": "npm run cb-init && extest setup-and-run --locale ru './out/test/cli/order-3.test.js' './out/test/cli/order-2.test.js' './out/test/cli/order-1.test.js' './out/test/**/!(clipboard)*.test.js' './out/test/system/clipboard.test.js' -u -i -r . -e ./test-extensions",
"ui-test:coverage": "MOCHA_GREP='order|clipboard|ExtensionsView|TitleBar' MOCHA_INVERT=true extest setup-and-run './out/test/**/*.test.js' -i -r . -e ./test-extensions --coverage"
},
"devDependencies": {
Expand Down
Loading