mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Re-apply prettier JS formatter
This commit is contained in:
@@ -1,40 +1,59 @@
|
||||
const path = require('path')
|
||||
const http = require('http')
|
||||
const temp = require('temp').track()
|
||||
const remote = require('remote')
|
||||
const {once} = require('underscore-plus')
|
||||
const {spawn} = require('child_process')
|
||||
const webdriverio = require('../../../script/node_modules/webdriverio')
|
||||
const path = require('path');
|
||||
const http = require('http');
|
||||
const temp = require('temp').track();
|
||||
const remote = require('remote');
|
||||
const { once } = require('underscore-plus');
|
||||
const { spawn } = require('child_process');
|
||||
const webdriverio = require('../../../script/node_modules/webdriverio');
|
||||
|
||||
const AtomPath = remote.process.argv[0]
|
||||
const AtomLauncherPath = path.join(__dirname, '..', 'helpers', 'atom-launcher.sh')
|
||||
const ChromedriverPath = path.resolve(__dirname, '..', '..', '..', 'script', 'node_modules', 'electron-chromedriver', 'bin', 'chromedriver')
|
||||
const ChromedriverPort = 9515
|
||||
const ChromedriverURLBase = '/wd/hub'
|
||||
const ChromedriverStatusURL = `http://localhost:${ChromedriverPort}${ChromedriverURLBase}/status`
|
||||
const AtomPath = remote.process.argv[0];
|
||||
const AtomLauncherPath = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'helpers',
|
||||
'atom-launcher.sh'
|
||||
);
|
||||
const ChromedriverPath = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'script',
|
||||
'node_modules',
|
||||
'electron-chromedriver',
|
||||
'bin',
|
||||
'chromedriver'
|
||||
);
|
||||
const ChromedriverPort = 9515;
|
||||
const ChromedriverURLBase = '/wd/hub';
|
||||
const ChromedriverStatusURL = `http://localhost:${ChromedriverPort}${ChromedriverURLBase}/status`;
|
||||
|
||||
const chromeDriverUp = done => {
|
||||
const checkStatus = () =>
|
||||
http.get(ChromedriverStatusURL, response => {
|
||||
if (response.statusCode === 200) {
|
||||
done()
|
||||
} else {
|
||||
chromeDriverUp(done)
|
||||
}
|
||||
}).on('error', () => chromeDriverUp(done))
|
||||
http
|
||||
.get(ChromedriverStatusURL, response => {
|
||||
if (response.statusCode === 200) {
|
||||
done();
|
||||
} else {
|
||||
chromeDriverUp(done);
|
||||
}
|
||||
})
|
||||
.on('error', () => chromeDriverUp(done));
|
||||
|
||||
setTimeout(checkStatus, 100)
|
||||
}
|
||||
setTimeout(checkStatus, 100);
|
||||
};
|
||||
|
||||
const chromeDriverDown = done => {
|
||||
const checkStatus = () =>
|
||||
http.get(ChromedriverStatusURL, response => chromeDriverDown(done)).on('error', done)
|
||||
http
|
||||
.get(ChromedriverStatusURL, response => chromeDriverDown(done))
|
||||
.on('error', done);
|
||||
|
||||
setTimeout(checkStatus, 100)
|
||||
}
|
||||
setTimeout(checkStatus, 100);
|
||||
};
|
||||
|
||||
const buildAtomClient = async (args, env) => {
|
||||
const userDataDir = temp.mkdirSync('atom-user-data-dir')
|
||||
const userDataDir = temp.mkdirSync('atom-user-data-dir');
|
||||
const client = await webdriverio.remote({
|
||||
host: 'localhost',
|
||||
port: ChromedriverPort,
|
||||
@@ -45,109 +64,132 @@ const buildAtomClient = async (args, env) => {
|
||||
args: [
|
||||
`atom-path=${AtomPath}`,
|
||||
`atom-args=${args.join(' ')}`,
|
||||
`atom-env=${Object.entries(env).map(([key, value]) => `${key}=${value}`).join(' ')}`,
|
||||
`atom-env=${Object.entries(env)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(' ')}`,
|
||||
'dev',
|
||||
'safe',
|
||||
`user-data-dir=${userDataDir}`
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
client.addCommand('waitForPaneItemCount', async function (count, timeout) {
|
||||
await this.waitUntil(() => this.execute(() => atom.workspace.getActivePane().getItems().length), timeout)
|
||||
})
|
||||
client.addCommand('treeViewRootDirectories', async function () {
|
||||
const treeViewElement = await this.$('.tree-view')
|
||||
await treeViewElement.waitForExist(10000)
|
||||
client.addCommand('waitForPaneItemCount', async function(count, timeout) {
|
||||
await this.waitUntil(
|
||||
() =>
|
||||
this.execute(() => atom.workspace.getActivePane().getItems().length),
|
||||
timeout
|
||||
);
|
||||
});
|
||||
client.addCommand('treeViewRootDirectories', async function() {
|
||||
const treeViewElement = await this.$('.tree-view');
|
||||
await treeViewElement.waitForExist(10000);
|
||||
return this.execute(() =>
|
||||
Array.from(document.querySelectorAll('.tree-view .project-root > .header .name'))
|
||||
.map(element => element.dataset.path)
|
||||
)
|
||||
})
|
||||
client.addCommand('dispatchCommand', async function (command) {
|
||||
return this.execute(async (command) => await atom.commands.dispatch(document.activeElement, command), command)
|
||||
})
|
||||
Array.from(
|
||||
document.querySelectorAll('.tree-view .project-root > .header .name')
|
||||
).map(element => element.dataset.path)
|
||||
);
|
||||
});
|
||||
client.addCommand('dispatchCommand', async function(command) {
|
||||
return this.execute(
|
||||
command => atom.commands.dispatch(document.activeElement, command),
|
||||
command
|
||||
);
|
||||
});
|
||||
|
||||
return client
|
||||
}
|
||||
return client;
|
||||
};
|
||||
|
||||
module.exports = function(args, env, fn) {
|
||||
let chromedriver, chromedriverLogs, chromedriverExit
|
||||
let chromedriver, chromedriverLogs, chromedriverExit;
|
||||
|
||||
runs(() => {
|
||||
chromedriver = spawn(ChromedriverPath, [
|
||||
'--verbose',
|
||||
`--port=${ChromedriverPort}`,
|
||||
`--url-base=${ChromedriverURLBase}`
|
||||
])
|
||||
]);
|
||||
|
||||
chromedriverLogs = []
|
||||
chromedriverLogs = [];
|
||||
chromedriverExit = new Promise(resolve => {
|
||||
let errorCode = null
|
||||
let errorCode = null;
|
||||
chromedriver.on('exit', (code, signal) => {
|
||||
if (signal == null) {
|
||||
errorCode = code
|
||||
errorCode = code;
|
||||
}
|
||||
})
|
||||
chromedriver.stderr.on('data', log => chromedriverLogs.push(log.toString()))
|
||||
chromedriver.stderr.on('close', () => resolve(errorCode))
|
||||
})
|
||||
})
|
||||
});
|
||||
chromedriver.stderr.on('data', log =>
|
||||
chromedriverLogs.push(log.toString())
|
||||
);
|
||||
chromedriver.stderr.on('close', () => resolve(errorCode));
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor('webdriver to start', chromeDriverUp, 15000)
|
||||
waitsFor('webdriver to start', chromeDriverUp, 15000);
|
||||
|
||||
waitsFor('tests to run', async done => {
|
||||
let client
|
||||
try {
|
||||
client = await buildAtomClient(args, env)
|
||||
} catch (error) {
|
||||
jasmine.getEnv().currentSpec.fail(`Unable to build Atom client.\n${error}`)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
waitsFor(
|
||||
'tests to run',
|
||||
async done => {
|
||||
const finish = once(async () => {
|
||||
await client.deleteSession();
|
||||
chromedriver.kill();
|
||||
|
||||
const finish = once(async () => {
|
||||
await client.deleteSession()
|
||||
chromedriver.kill()
|
||||
const errorCode = await chromedriverExit;
|
||||
if (errorCode != null) {
|
||||
jasmine.getEnv().currentSpec
|
||||
.fail(`Chromedriver exited with code ${errorCode}.
|
||||
Logs:\n${chromedriverLogs.join('\n')}`);
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
const errorCode = await chromedriverExit
|
||||
if (errorCode != null) {
|
||||
jasmine.getEnv().currentSpec.fail(`Chromedriver exited with code ${errorCode}.
|
||||
Logs:\n${chromedriverLogs.join('\n')}`)
|
||||
let client;
|
||||
try {
|
||||
client = await buildAtomClient(args, env);
|
||||
} catch (error) {
|
||||
jasmine
|
||||
.getEnv()
|
||||
.currentSpec.fail(`Unable to build Atom client.\n${error}`);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
done()
|
||||
})
|
||||
|
||||
try {
|
||||
await client.waitUntil(async function () {
|
||||
const handles = await this.getWindowHandles()
|
||||
return handles.length > 0
|
||||
}, 10000)
|
||||
} catch (error) {
|
||||
jasmine.getEnv().currentSpec.fail(`Unable to locate windows.\n\n${error}`)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
try {
|
||||
await client.waitUntil(async function() {
|
||||
const handles = await this.getWindowHandles();
|
||||
return handles.length > 0;
|
||||
}, 10000);
|
||||
} catch (error) {
|
||||
jasmine
|
||||
.getEnv()
|
||||
.currentSpec.fail(`Unable to locate windows.\n\n${error}`);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const workspaceElement = await client.$('atom-workspace')
|
||||
await workspaceElement.waitForExist(10000)
|
||||
} catch (error) {
|
||||
jasmine.getEnv().currentSpec.fail(`Unable to find workspace element.\n\n${error}`)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
try {
|
||||
const workspaceElement = await client.$('atom-workspace');
|
||||
await workspaceElement.waitForExist(10000);
|
||||
} catch (error) {
|
||||
jasmine
|
||||
.getEnv()
|
||||
.currentSpec.fail(`Unable to find workspace element.\n\n${error}`);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await fn(client)
|
||||
} catch (error) {
|
||||
jasmine.getEnv().currentSpec.fail(error)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
finish()
|
||||
}, 30000)
|
||||
try {
|
||||
await fn(client);
|
||||
} catch (error) {
|
||||
jasmine.getEnv().currentSpec.fail(error);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
finish();
|
||||
},
|
||||
30000
|
||||
);
|
||||
|
||||
waitsFor('webdriver to stop', chromeDriverDown, 15000)
|
||||
}
|
||||
waitsFor('webdriver to stop', chromeDriverDown, 15000);
|
||||
};
|
||||
|
||||
@@ -1,58 +1,62 @@
|
||||
const fs = require('fs-plus')
|
||||
const path = require('path')
|
||||
const season = require('season')
|
||||
const temp = require('temp').track()
|
||||
const runAtom = require('./helpers/start-atom')
|
||||
const fs = require('fs-plus');
|
||||
const path = require('path');
|
||||
const season = require('season');
|
||||
const temp = require('temp').track();
|
||||
const runAtom = require('./helpers/start-atom');
|
||||
|
||||
describe('Smoke Test', () => {
|
||||
// Fails on win32
|
||||
if (process.platform !== 'darwin') {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
const atomHome = temp.mkdirSync('atom-home')
|
||||
const atomHome = temp.mkdirSync('atom-home');
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.useRealClock()
|
||||
jasmine.useRealClock();
|
||||
season.writeFileSync(path.join(atomHome, 'config.cson'), {
|
||||
'*': {
|
||||
welcome: {showOnStartup: false},
|
||||
welcome: { showOnStartup: false },
|
||||
core: {
|
||||
telemetryConsent: 'no',
|
||||
disabledPackages: ['github']
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('can open a file in Atom and perform basic operations on it', async () => {
|
||||
const tempDirPath = temp.mkdirSync('empty-dir')
|
||||
const filePath = path.join(tempDirPath, 'new-file')
|
||||
const tempDirPath = temp.mkdirSync('empty-dir');
|
||||
const filePath = path.join(tempDirPath, 'new-file');
|
||||
|
||||
fs.writeFileSync(filePath, '', {encoding: 'utf8'})
|
||||
fs.writeFileSync(filePath, '', { encoding: 'utf8' });
|
||||
|
||||
runAtom([tempDirPath], {ATOM_HOME: atomHome}, async client => {
|
||||
const roots = await client.treeViewRootDirectories()
|
||||
expect(roots).toEqual([tempDirPath])
|
||||
runAtom([tempDirPath], { ATOM_HOME: atomHome }, async client => {
|
||||
const roots = await client.treeViewRootDirectories();
|
||||
expect(roots).toEqual([tempDirPath]);
|
||||
|
||||
await client.execute(async filePath => await atom.workspace.open(filePath), filePath)
|
||||
await client.execute(filePath => atom.workspace.open(filePath), filePath);
|
||||
|
||||
const textEditorElement = await client.$('atom-text-editor')
|
||||
await textEditorElement.waitForExist(5000)
|
||||
const textEditorElement = await client.$('atom-text-editor');
|
||||
await textEditorElement.waitForExist(5000);
|
||||
|
||||
await client.waitForPaneItemCount(1, 1000)
|
||||
await client.waitForPaneItemCount(1, 1000);
|
||||
|
||||
await textEditorElement.click()
|
||||
await textEditorElement.click();
|
||||
|
||||
const closestElement = await client.execute(() => document.activeElement.closest('atom-text-editor'))
|
||||
expect(closestElement).not.toBeNull()
|
||||
const closestElement = await client.execute(() =>
|
||||
document.activeElement.closest('atom-text-editor')
|
||||
);
|
||||
expect(closestElement).not.toBeNull();
|
||||
|
||||
await client.keys('Hello!')
|
||||
await client.keys('Hello!');
|
||||
|
||||
const text = await client.execute(() => atom.workspace.getActiveTextEditor().getText())
|
||||
expect(text).toBe('Hello!')
|
||||
const text = await client.execute(() =>
|
||||
atom.workspace.getActiveTextEditor().getText()
|
||||
);
|
||||
expect(text).toBe('Hello!');
|
||||
|
||||
await client.dispatchCommand('editor:delete-line')
|
||||
})
|
||||
})
|
||||
})
|
||||
await client.dispatchCommand('editor:delete-line');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user