<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import * as http from 'http';
import * as path from 'path';
import * as fs from 'fs';
import * as stripJsonComments from 'strip-json-comments';
import { Application } from '../../application';

export function setup() {
	describe('Debug', () => {
		it('configure launch json', async function () {
			const app = this.app as Application;

			await app.workbench.debug.openDebugViewlet();
			await app.workbench.quickopen.openFile('app.js');
			await app.workbench.debug.configure();

			const launchJsonPath = path.join(app.workspacePath, '.vscode', 'launch.json');
			const content = fs.readFileSync(launchJsonPath, 'utf8');
			const config = JSON.parse(stripJsonComments(content));
			config.configurations[0].protocol = 'inspector';
			fs.writeFileSync(launchJsonPath, JSON.stringify(config, undefined, 4), 'utf8');

			await app.workbench.editor.waitForEditorContents('launch.json', contents => /"protocol": "inspector"/.test(contents));

			assert.equal(config.configurations[0].request, 'launch');
			assert.equal(config.configurations[0].type, 'node');
			if (process.platform === 'win32') {
				assert.equal(config.configurations[0].program, '${workspaceFolder}\\bin\\www');
			} else {
				assert.equal(config.configurations[0].program, '${workspaceFolder}/bin/www');
			}
		});

		it('breakpoints', async function () {
			const app = this.app as Application;

			await app.workbench.quickopen.openFile('index.js');
			await app.workbench.debug.setBreakpointOnLine(6);
		});

		let port: number;
		it('start debugging', async function () {
			const app = this.app as Application;

			port = await app.workbench.debug.startDebugging();

			await new Promise((c, e) => {
				const request = http.get(`http://localhost:${port}`);
				request.on('error', e);
				app.workbench.debug.waitForStackFrame(sf => /index\.js$/.test(sf.name) && sf.lineNumber === 6, 'looking for index.js and line 6').then(c, e);
			});
		});<commit_msg>debug smoke: Force load from disk since file events are sometimes missing<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import * as http from 'http';
import * as path from 'path';
import * as fs from 'fs';
import * as stripJsonComments from 'strip-json-comments';
import { Application } from '../../application';

export function setup() {
	describe('Debug', () => {
		it('configure launch json', async function () {
			const app = this.app as Application;

			await app.workbench.debug.openDebugViewlet();
			await app.workbench.quickopen.openFile('app.js');
			await app.workbench.debug.configure();

			const launchJsonPath = path.join(app.workspacePath, '.vscode', 'launch.json');
			const content = fs.readFileSync(launchJsonPath, 'utf8');
			const config = JSON.parse(stripJsonComments(content));
			config.configurations[0].protocol = 'inspector';
			fs.writeFileSync(launchJsonPath, JSON.stringify(config, undefined, 4), 'utf8');

			// force load from disk since file events are sometimes missing
			await app.workbench.quickopen.runCommand('File: Revert File');
			await app.workbench.editor.waitForEditorContents('launch.json', contents => /"protocol": "inspector"/.test(contents));

			assert.equal(config.configurations[0].request, 'launch');
			assert.equal(config.configurations[0].type, 'node');
			if (process.platform === 'win32') {
				assert.equal(config.configurations[0].program, '${workspaceFolder}\\bin\\www');
			} else {
				assert.equal(config.configurations[0].program, '${workspaceFolder}/bin/www');
			}
		});

		it('breakpoints', async function () {
			const app = this.app as Application;

			await app.workbench.quickopen.openFile('index.js');
			await app.workbench.debug.setBreakpointOnLine(6);
		});

		let port: number;
		it('start debugging', async function () {
			const app = this.app as Application;

			port = await app.workbench.debug.startDebugging();

			await new Promise((c, e) => {
				const request = http.get(`http://localhost:${port}`);
				request.on('error', e);
				app.workbench.debug.waitForStackFrame(sf => /index\.js$/.test(sf.name) && sf.lineNumber === 6, 'looking for index.js and line 6').then(c, e);
			});
		});
{'fraction_non_alphanumeric': 0.22167386387003907, 'fraction_numerical': 0.005346493933785729, 'mean_word_length': 3.0, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613710', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1353, 'n_words': 333}