First try to modernize the test runner

This commit is contained in:
Maurício Szabo 2023-05-16 10:48:15 -03:00
parent 4a6f752ed1
commit 78fb1f8084
4 changed files with 129 additions and 2 deletions

View File

@ -365,7 +365,7 @@ module.exports = class AtomApplication extends EventEmitter {
} }
if (test) { if (test) {
return this.runTests({ return this.runTestsLegacy({
headless: true, headless: true,
devMode, devMode,
resourcePath: this.resourcePath, resourcePath: this.resourcePath,
@ -899,6 +899,24 @@ module.exports = class AtomApplication extends EventEmitter {
ipcHelpers.on( ipcHelpers.on(
ipcMain, ipcMain,
'run-package-specs', 'run-package-specs',
(event, packageSpecPath, options = {}) => {
this.runTestsLegacy(
Object.assign(
{
resourcePath: this.devResourcePath,
pathsToOpen: [packageSpecPath],
headless: false
},
options
)
);
}
)
);
this.disposable.add(
ipcHelpers.on(
ipcMain,
'run-package-tests',
(event, packageSpecPath, options = {}) => { (event, packageSpecPath, options = {}) => {
this.runTests( this.runTests(
Object.assign( Object.assign(
@ -1693,6 +1711,75 @@ module.exports = class AtomApplication extends EventEmitter {
return this.packages; return this.packages;
} }
// Opens up a new {AtomWindow} to run specs within.
//
// options -
// :headless - A Boolean that, if true, will close the window upon
// completion.
// :resourcePath - The path to include specs from.
// :specPath - The directory to load specs from.
runTests({
headless,
resourcePath,
executedFrom,
pathsToOpen,
logFile,
env
}) {
const testPaths = [];
if (pathsToOpen != null) {
for (let pathToOpen of pathsToOpen) {
testPaths.push(path.resolve(executedFrom, fs.normalize(pathToOpen)));
}
}
if (testPaths.length === 0) {
process.stderr.write('Error: Specify at least one test path\n\n');
process.exit(1);
}
const windowInitializationScript = path.join(
__dirname, "..", "initialize-new-test-window"
);
// {
// windowInitializationScript: '/home/mauricio/projects/pulsar_repos/pulsar/src/initialize-test-window.js',
// resourcePath: '/home/mauricio/projects/pulsar_repos/pulsar',
// headless: false,
// isSpec: true,
// devMode: true,
// testRunnerPath: '/home/mauricio/projects/pulsar_repos/pulsar/spec/jasmine-test-runner.js',
// legacyTestRunnerPath: '/home/mauricio/projects/pulsar_repos/pulsar/spec/jasmine-test-runner.js',
// testPaths: [ '/home/mauricio/projects/pulsar_repos/pulsar/spec' ],
// logFile: undefined,
// safeMode: false,
// env: undefined
// }
// WAAA {
// windowInitializationScript: '/home/mauricio/projects/pulsar_repos/pulsar/src/initialize-new-test-window',
// resourcePath: '/home/mauricio/projects/pulsar_repos/pulsar',
// headless: false,
// isSpec: true,
// devMode: true,
// testPaths: [ '/home/mauricio/projects/pulsar_repos/pulsar/spec' ],
// logFile: undefined,
// env: undefined
// }
const window = this.createWindow({
windowInitializationScript,
resourcePath,
headless,
isSpec: true,
devMode: true,
testPaths,
logFile,
env
});
this.addWindow(window);
if (env) window.replaceEnvironment(env);
return window;
}
// Opens up a new {AtomWindow} to run specs within. // Opens up a new {AtomWindow} to run specs within.
// //
// options - // options -
@ -1702,7 +1789,7 @@ module.exports = class AtomApplication extends EventEmitter {
// :specPath - The directory to load specs from. // :specPath - The directory to load specs from.
// :safeMode - A Boolean that, if true, won't run specs from ~/.pulsar/packages // :safeMode - A Boolean that, if true, won't run specs from ~/.pulsar/packages
// and ~/.pulsar/dev/packages, defaults to false. // and ~/.pulsar/dev/packages, defaults to false.
runTests({ runTestsLegacy({
headless, headless,
resourcePath, resourcePath,
executedFrom, executedFrom,
@ -1757,6 +1844,19 @@ module.exports = class AtomApplication extends EventEmitter {
if (safeMode == null) { if (safeMode == null) {
safeMode = false; safeMode = false;
} }
console.log("AW", {
windowInitializationScript,
resourcePath,
headless,
isSpec,
devMode,
testRunnerPath,
legacyTestRunnerPath,
testPaths,
logFile,
safeMode,
env
})
const window = this.createWindow({ const window = this.createWindow({
windowInitializationScript, windowInitializationScript,
resourcePath, resourcePath,

View File

@ -144,6 +144,9 @@ module.exports = function({commandRegistry, commandInstaller, config, notificati
'window:run-package-specs': function() { 'window:run-package-specs': function() {
return this.runPackageSpecs(); return this.runPackageSpecs();
}, },
'window:run-package-tests': function() {
return this.runPackageTests();
},
'window:toggle-left-dock': function() { 'window:toggle-left-dock': function() {
return this.getModel().getLeftDock().toggle(); return this.getModel().getLeftDock().toggle();
}, },

View File

@ -446,6 +446,29 @@ class WorkspaceElement extends HTMLElement {
ipcRenderer.send('run-package-specs', specPath, options); ipcRenderer.send('run-package-specs', specPath, options);
} }
} }
runPackageTests(options = {}) {
const activePaneItem = this.model.getActivePaneItem();
const activePath =
activePaneItem && typeof activePaneItem.getPath === 'function'
? activePaneItem.getPath()
: null;
let projectPath;
if (activePath != null) {
[projectPath] = this.project.relativizePath(activePath);
} else {
[projectPath] = this.project.getPaths();
}
if (projectPath) {
let specPath = path.join(projectPath, 'spec');
const testPath = path.join(projectPath, 'test');
if (!fs.existsSync(specPath) && fs.existsSync(testPath)) {
specPath = testPath;
}
ipcRenderer.send('run-package-tests', specPath, options);
}
}
} }
function isTab(element) { function isTab(element) {

View File

@ -210,6 +210,7 @@ module.exports = class Workspace extends Model {
this.scandalDirectorySearcher = new DefaultDirectorySearcher(); this.scandalDirectorySearcher = new DefaultDirectorySearcher();
this.ripgrepDirectorySearcher = new RipgrepDirectorySearcher(); this.ripgrepDirectorySearcher = new RipgrepDirectorySearcher();
console.log("PACKAGE?", this.packageManager)
this.consumeServices(this.packageManager); this.consumeServices(this.packageManager);
this.paneContainers = { this.paneContainers = {