chore: move ts-smoke tests to core (#16930)

* chore: move ts smoke tests to core

* fix: fix paths for tsconfig / ts-smoke runner

* update ts-defs version

* do not lintr
This commit is contained in:
Shelley Vohr 2019-02-13 15:24:28 -08:00 committed by Samuel Attard
parent 95214fcd4b
commit 319c2853df
7 changed files with 1470 additions and 3 deletions

View file

@ -47,6 +47,8 @@ The `globalShortcut` module has the following methods:
* `accelerator` [Accelerator](accelerator.md)
* `callback` Function
Returns `Boolean` - Whether or not the shortcut was registered successfully.
Registers a global shortcut of `accelerator`. The `callback` is called when
the registered shortcut is pressed by the user.

View file

@ -15,7 +15,7 @@
"dotenv-safe": "^4.0.4",
"dugite": "^1.45.0",
"electron-docs-linter": "^2.4.0",
"electron-typescript-definitions": "^6.0.0",
"electron-typescript-definitions": "^7.0.0",
"eslint": "^5.13.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-mocha": "^5.2.0",
@ -57,7 +57,7 @@
"lint:docs-relative-links": "python ./script/check-relative-doc-links.py",
"lint:js-in-markdown": "standard-markdown docs",
"create-api-json": "electron-docs-linter docs --outfile=electron-api.json",
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=electron-api.json --out=electron.d.ts",
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=electron-api.json --out=electron.d.ts && node spec/ts-smoke/runner.js",
"gn-typescript-definitions": "npm run create-typescript-definitions && cp electron.d.ts",
"preinstall": "node -e 'process.exit(0)'",
"precommit": "lint-staged",

View file

@ -29,7 +29,10 @@ const BLACKLIST = new Set([
['atom', 'common', 'common_message_generator.cc'],
['atom', 'common', 'common_message_generator.h'],
['atom', 'common', 'node_includes.h'],
['spec', 'static', 'jquery-2.0.3.min.js']
['spec', 'static', 'jquery-2.0.3.min.js'],
['spec', 'ts-smoke', 'electron', 'main.ts'],
['spec', 'ts-smoke', 'electron', 'renderer.ts'],
['spec', 'ts-smoke', 'runner.js']
].map(tokens => path.join(SOURCE_ROOT, ...tokens)))
function spawnAndCheckExitCode (cmd, args, opts) {

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,266 @@
import {
ipcRenderer,
remote,
webFrame,
clipboard,
crashReporter,
nativeImage,
screen,
shell
} from 'electron'
import * as fs from 'fs'
// In renderer process (web page).
// https://github.com/atom/electron/blob/master/docs/api/ipc-renderer.md
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
ipcRenderer.on('asynchronous-reply', (event: Electron.Event, arg: any) => {
console.log(arg) // prints "pong"
event.sender.send('another-message', 'Hello World!')
})
ipcRenderer.send('asynchronous-message', 'ping')
// remote
// https://github.com/atom/electron/blob/master/docs/api/remote.md
const BrowserWindow = remote.BrowserWindow
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadURL('https://github.com')
remote.getCurrentWindow().on('close', () => {
// blabla...
})
remote.getCurrentWindow().capturePage(buf => {
fs.writeFile('/tmp/screenshot.png', buf, err => {
console.log(err)
})
})
remote.getCurrentWebContents().print()
remote.getCurrentWindow().capturePage(buf => {
remote.require('fs').writeFile('/tmp/screenshot.png', buf, (err: Error) => {
console.log(err)
})
})
// web-frame
// https://github.com/atom/electron/blob/master/docs/api/web-frame.md
webFrame.setZoomFactor(2)
console.log(webFrame.getZoomFactor())
webFrame.setZoomLevel(200)
console.log(webFrame.getZoomLevel())
webFrame.setVisualZoomLevelLimits(50, 200)
webFrame.setLayoutZoomLevelLimits(50, 200)
webFrame.setSpellCheckProvider('en-US', {
spellCheck (words, callback) {
setTimeout(() => {
const spellchecker = require('spellchecker')
const misspelled = words.filter(x => spellchecker.isMisspelled(x))
callback(misspelled)
}, 0)
}
})
webFrame.insertText('text')
webFrame.executeJavaScript('JSON.stringify({})', false, (result) => {
console.log(result)
}).then((result: string) => console.log('OK:' + result))
console.log(webFrame.getResourceUsage())
webFrame.clearCache()
// clipboard
// https://github.com/atom/electron/blob/master/docs/api/clipboard.md
clipboard.writeText('Example String')
clipboard.writeText('Example String', 'selection')
console.log(clipboard.readText('selection'))
console.log(clipboard.availableFormats())
clipboard.clear()
clipboard.write({
html: '<html></html>',
text: 'Hello World!',
bookmark: 'Bookmark name',
image: clipboard.readImage()
})
// crash-reporter
// https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md
crashReporter.start({
productName: 'YourName',
companyName: 'YourCompany',
submitURL: 'https://your-domain.com/url-to-submit',
uploadToServer: true
})
// desktopCapturer
// https://github.com/atom/electron/blob/master/docs/api/desktop-capturer.md
const desktopCapturer = require('electron').desktopCapturer
desktopCapturer.getSources({ types: ['window', 'screen'] }, function (error, sources) {
if (error) throw error
for (let i = 0; i < sources.length; ++i) {
if (sources[i].name == 'Electron') {
(navigator as any).webkitGetUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sources[i].id,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720
}
}
}, gotStream, getUserMediaError)
return
}
}
})
function gotStream (stream: any) {
(document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream)
}
function getUserMediaError (error: Error) {
console.log('getUserMediaError', error)
}
// File object
// https://github.com/atom/electron/blob/master/docs/api/file-object.md
/*
<div id="holder">
Drag your file here
</div>
*/
const holder = document.getElementById('holder')
holder.ondragover = function () {
return false
}
holder.ondragleave = holder.ondragend = function () {
return false
}
holder.ondrop = function (e) {
e.preventDefault()
const file = e.dataTransfer.files[0]
console.log('File you dragged here is', file.path)
return false
}
// nativeImage
// https://github.com/atom/electron/blob/master/docs/api/native-image.md
const Tray = remote.Tray
const appIcon2 = new Tray('/Users/somebody/images/icon.png')
const window2 = new BrowserWindow({ icon: '/Users/somebody/images/window.png' })
const image = clipboard.readImage()
const appIcon3 = new Tray(image)
const appIcon4 = new Tray('/Users/somebody/images/icon.png')
// https://github.com/electron/electron/blob/master/docs/api/process.md
// preload.js
const _setImmediate = setImmediate
const _clearImmediate = clearImmediate
process.once('loaded', function () {
global.setImmediate = _setImmediate
global.clearImmediate = _clearImmediate
})
// screen
// https://github.com/atom/electron/blob/master/docs/api/screen.md
const app = remote.app
let mainWindow: Electron.BrowserWindow = null
app.on('ready', () => {
const size = screen.getPrimaryDisplay().workAreaSize
mainWindow = new BrowserWindow({ width: size.width, height: size.height })
})
app.on('ready', () => {
const displays = screen.getAllDisplays()
let externalDisplay: any = null
for (const i in displays) {
if (displays[i].bounds.x > 0 || displays[i].bounds.y > 0) {
externalDisplay = displays[i]
break
}
}
if (externalDisplay) {
mainWindow = new BrowserWindow({
x: externalDisplay.bounds.x + 50,
y: externalDisplay.bounds.y + 50
})
}
})
// shell
// https://github.com/atom/electron/blob/master/docs/api/shell.md
shell.openExternal('https://github.com')
// <webview>
// https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md
const webview = document.createElement('webview')
webview.loadURL('https://github.com')
webview.addEventListener('console-message', function (e) {
console.log('Guest page logged a message:', e.message)
})
webview.addEventListener('found-in-page', function (e) {
if (e.result.finalUpdate) {
webview.stopFindInPage('keepSelection')
}
})
const requestId = webview.findInPage('test')
webview.addEventListener('new-window', function (e) {
require('electron').shell.openExternal(e.url)
})
webview.addEventListener('close', function () {
webview.src = 'about:blank'
})
// In embedder page.
webview.addEventListener('ipc-message', function (event) {
console.log(event.channel) // Prints "pong"
})
webview.send('ping')
webview.capturePage((image) => { console.log(image) })
{
const opened: boolean = webview.isDevToolsOpened()
const focused: boolean = webview.isDevToolsFocused()
const focused2: boolean = webview.getWebContents().isFocused()
}
// In guest page.
ipcRenderer.on('ping', function () {
ipcRenderer.sendToHost('pong')
})

18
spec/ts-smoke/runner.js Normal file
View file

@ -0,0 +1,18 @@
const path = require('path')
const childProcess = require('child_process')
const typeCheck = () => {
const tscExec = path.resolve(require.resolve('typescript'), '../../bin/tsc')
const tscChild = childProcess.spawn(process.execPath, [tscExec, '--project', './ts-smoke/tsconfig.json'], {
cwd: path.resolve(__dirname, '../')
})
tscChild.stdout.on('data', d => console.log(d.toString()))
tscChild.stderr.on('data', d => console.error(d.toString()))
tscChild.on('exit', (tscStatus) => {
if (tscStatus !== 0) {
process.exit(tscStatus)
}
})
}
typeCheck()

View file

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"electron/main.ts",
"electron/renderer.ts",
"../../electron.d.ts"
]
}