test: enable linting of ts-smoke and fix all issues (#37322)
This commit is contained in:
		
					parent
					
						
							
								ee87438d28
							
						
					
				
			
			
				commit
				
					
						e34cc6f48c
					
				
			
		
					 4 changed files with 495 additions and 478 deletions
				
			
		|  | @ -22,10 +22,7 @@ process.env.PATH = `${process.env.PATH}${path.delimiter}${DEPOT_TOOLS}`; | ||||||
| const IGNORELIST = new Set([ | const IGNORELIST = new Set([ | ||||||
|   ['shell', 'browser', 'resources', 'win', 'resource.h'], |   ['shell', 'browser', 'resources', 'win', 'resource.h'], | ||||||
|   ['shell', 'common', 'node_includes.h'], |   ['shell', 'common', 'node_includes.h'], | ||||||
|   ['spec', 'fixtures', 'pages', 'jquery-3.6.0.min.js'], |   ['spec', 'fixtures', 'pages', 'jquery-3.6.0.min.js'] | ||||||
|   ['spec', 'ts-smoke', 'electron', 'main.ts'], |  | ||||||
|   ['spec', 'ts-smoke', 'electron', 'renderer.ts'], |  | ||||||
|   ['spec', 'ts-smoke', 'runner.js'] |  | ||||||
| ].map(tokens => path.join(ELECTRON_ROOT, ...tokens))); | ].map(tokens => path.join(ELECTRON_ROOT, ...tokens))); | ||||||
| 
 | 
 | ||||||
| const IS_WINDOWS = process.platform === 'win32'; | const IS_WINDOWS = process.platform === 'win32'; | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -6,67 +6,65 @@ import { | ||||||
|   clipboard, |   clipboard, | ||||||
|   crashReporter, |   crashReporter, | ||||||
|   shell |   shell | ||||||
| } from 'electron' | } from 'electron'; | ||||||
| 
 |  | ||||||
| import * as fs from 'fs' |  | ||||||
| 
 | 
 | ||||||
| // In renderer process (web page).
 | // In renderer process (web page).
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/ipc-renderer.md
 | // https://github.com/electron/electron/blob/main/docs/api/ipc-renderer.md
 | ||||||
| console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
 | console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
 | ||||||
| 
 | 
 | ||||||
| ipcRenderer.on('asynchronous-reply', (event, arg: any) => { | ipcRenderer.on('asynchronous-reply', (event, arg: any) => { | ||||||
|   console.log(arg) // prints "pong"
 |   console.log(arg); // prints "pong"
 | ||||||
|   event.sender.send('another-message', 'Hello World!') |   event.sender.send('another-message', 'Hello World!'); | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| ipcRenderer.send('asynchronous-message', 'ping') | ipcRenderer.send('asynchronous-message', 'ping'); | ||||||
| 
 | 
 | ||||||
| // web-frame
 | // web-frame
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/web-frame.md
 | // https://github.com/electron/electron/blob/main/docs/api/web-frame.md
 | ||||||
| 
 | 
 | ||||||
| webFrame.setZoomFactor(2) | webFrame.setZoomFactor(2); | ||||||
| console.log(webFrame.getZoomFactor()) | console.log(webFrame.getZoomFactor()); | ||||||
| 
 | 
 | ||||||
| webFrame.setZoomLevel(200) | webFrame.setZoomLevel(200); | ||||||
| console.log(webFrame.getZoomLevel()) | console.log(webFrame.getZoomLevel()); | ||||||
| 
 | 
 | ||||||
| webFrame.setVisualZoomLevelLimits(50, 200) | webFrame.setVisualZoomLevelLimits(50, 200); | ||||||
| 
 | 
 | ||||||
| webFrame.setSpellCheckProvider('en-US', { | webFrame.setSpellCheckProvider('en-US', { | ||||||
|   spellCheck (words, callback) { |   spellCheck (words, callback) { | ||||||
|     setTimeout(() => { |     setTimeout(() => { | ||||||
|       const spellchecker = require('spellchecker') |       const spellchecker = require('spellchecker'); | ||||||
|       const misspelled = words.filter(x => spellchecker.isMisspelled(x)) |       const misspelled = words.filter(x => spellchecker.isMisspelled(x)); | ||||||
|       callback(misspelled) |       callback(misspelled); | ||||||
|     }, 0) |     }, 0); | ||||||
|   } |   } | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| webFrame.insertText('text') | webFrame.insertText('text'); | ||||||
| 
 | 
 | ||||||
| webFrame.executeJavaScript('return true;').then((v: boolean) => console.log(v)) | webFrame.executeJavaScript('return true;').then((v: boolean) => console.log(v)); | ||||||
| webFrame.executeJavaScript('return true;', true).then((v: boolean) => console.log(v)) | webFrame.executeJavaScript('return true;', true).then((v: boolean) => console.log(v)); | ||||||
| webFrame.executeJavaScript('return true;', true) | webFrame.executeJavaScript('return true;', true); | ||||||
| webFrame.executeJavaScript('return true;', true).then((result: boolean) => console.log(result)) | webFrame.executeJavaScript('return true;', true).then((result: boolean) => console.log(result)); | ||||||
| 
 | 
 | ||||||
| console.log(webFrame.getResourceUsage()) | console.log(webFrame.getResourceUsage()); | ||||||
| webFrame.clearCache() | webFrame.clearCache(); | ||||||
| 
 | 
 | ||||||
| // clipboard
 | // clipboard
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/clipboard.md
 | // https://github.com/electron/electron/blob/main/docs/api/clipboard.md
 | ||||||
| 
 | 
 | ||||||
| clipboard.writeText('Example String') | clipboard.writeText('Example String'); | ||||||
| clipboard.writeText('Example String', 'selection') | clipboard.writeText('Example String', 'selection'); | ||||||
| console.log(clipboard.readText('selection')) | console.log(clipboard.readText('selection')); | ||||||
| console.log(clipboard.availableFormats()) | console.log(clipboard.availableFormats()); | ||||||
| clipboard.clear() | clipboard.clear(); | ||||||
| 
 | 
 | ||||||
| clipboard.write({ | clipboard.write({ | ||||||
|   html: '<html></html>', |   html: '<html></html>', | ||||||
|   text: 'Hello World!', |   text: 'Hello World!', | ||||||
|   bookmark: 'Bookmark name', |   bookmark: 'Bookmark name', | ||||||
|   image: clipboard.readImage() |   image: clipboard.readImage() | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| // crash-reporter
 | // crash-reporter
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/crash-reporter.md
 | // https://github.com/electron/electron/blob/main/docs/api/crash-reporter.md
 | ||||||
|  | @ -76,14 +74,14 @@ crashReporter.start({ | ||||||
|   companyName: 'YourCompany', |   companyName: 'YourCompany', | ||||||
|   submitURL: 'https://your-domain.com/url-to-submit', |   submitURL: 'https://your-domain.com/url-to-submit', | ||||||
|   uploadToServer: true |   uploadToServer: true | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| // desktopCapturer
 | // desktopCapturer
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md
 | // https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md
 | ||||||
| 
 | 
 | ||||||
| desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => { | desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => { | ||||||
|   for (let i = 0; i < sources.length; ++i) { |   for (let i = 0; i < sources.length; ++i) { | ||||||
|     if (sources[i].name == 'Electron') { |     if (sources[i].name === 'Electron') { | ||||||
|       (navigator as any).webkitGetUserMedia({ |       (navigator as any).webkitGetUserMedia({ | ||||||
|         audio: false, |         audio: false, | ||||||
|         video: { |         video: { | ||||||
|  | @ -96,18 +94,18 @@ desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => { | ||||||
|             maxHeight: 720 |             maxHeight: 720 | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       }, gotStream, getUserMediaError) |       }, gotStream, getUserMediaError); | ||||||
|       return |       return; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| function gotStream (stream: any) { | function gotStream (stream: any) { | ||||||
|   (document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream) |   (document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function getUserMediaError (error: Error) { | function getUserMediaError (error: Error) { | ||||||
|   console.log('getUserMediaError', error) |   console.log('getUserMediaError', error); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // File object
 | // File object
 | ||||||
|  | @ -119,78 +117,81 @@ function getUserMediaError (error: Error) { | ||||||
| </div> | </div> | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| const holder = document.getElementById('holder') | const holder = document.getElementById('holder'); | ||||||
| 
 | 
 | ||||||
| holder.ondragover = function () { | holder.ondragover = function () { | ||||||
|   return false |   return false; | ||||||
| } | }; | ||||||
| 
 | 
 | ||||||
| holder.ondragleave = holder.ondragend = function () { | holder.ondragleave = holder.ondragend = function () { | ||||||
|   return false |   return false; | ||||||
| } | }; | ||||||
| 
 | 
 | ||||||
| holder.ondrop = function (e) { | holder.ondrop = function (e) { | ||||||
|   e.preventDefault() |   e.preventDefault(); | ||||||
|   const file = e.dataTransfer.files[0] |   const file = e.dataTransfer.files[0]; | ||||||
|   console.log('File you dragged here is', file.path) |   console.log('File you dragged here is', file.path); | ||||||
|   return false |   return false; | ||||||
| } | }; | ||||||
| 
 | 
 | ||||||
| // nativeImage
 | // nativeImage
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/native-image.md
 | // https://github.com/electron/electron/blob/main/docs/api/native-image.md
 | ||||||
| 
 | 
 | ||||||
| const image = clipboard.readImage() | const image = clipboard.readImage(); | ||||||
|  | console.log(image.getSize()); | ||||||
| 
 | 
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/process.md
 | // https://github.com/electron/electron/blob/main/docs/api/process.md
 | ||||||
| 
 | 
 | ||||||
| // preload.js
 | // preload.js
 | ||||||
| const _setImmediate = setImmediate | const _setImmediate = setImmediate; | ||||||
| const _clearImmediate = clearImmediate | const _clearImmediate = clearImmediate; | ||||||
| process.once('loaded', function () { | process.once('loaded', function () { | ||||||
|   global.setImmediate = _setImmediate |   global.setImmediate = _setImmediate; | ||||||
|   global.clearImmediate = _clearImmediate |   global.clearImmediate = _clearImmediate; | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| // shell
 | // shell
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/shell.md
 | // https://github.com/electron/electron/blob/main/docs/api/shell.md
 | ||||||
| 
 | 
 | ||||||
| shell.openExternal('https://github.com').then(() => {}) | shell.openExternal('https://github.com').then(() => {}); | ||||||
| 
 | 
 | ||||||
| // <webview>
 | // <webview>
 | ||||||
| // https://github.com/electron/electron/blob/main/docs/api/webview-tag.md
 | // https://github.com/electron/electron/blob/main/docs/api/webview-tag.md
 | ||||||
| 
 | 
 | ||||||
| const webview = document.createElement('webview') | const webview = document.createElement('webview'); | ||||||
| webview.loadURL('https://github.com') | webview.loadURL('https://github.com'); | ||||||
| 
 | 
 | ||||||
| webview.addEventListener('console-message', function (e) { | webview.addEventListener('console-message', function (e) { | ||||||
|   console.log('Guest page logged a message:', e.message) |   console.log('Guest page logged a message:', e.message); | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| webview.addEventListener('found-in-page', function (e) { | webview.addEventListener('found-in-page', function (e) { | ||||||
|   if (e.result.finalUpdate) { |   if (e.result.finalUpdate) { | ||||||
|     webview.stopFindInPage('keepSelection') |     webview.stopFindInPage('keepSelection'); | ||||||
|   } |   } | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| const requestId = webview.findInPage('test') | const requestId = webview.findInPage('test'); | ||||||
|  | console.log(requestId); | ||||||
| 
 | 
 | ||||||
| webview.addEventListener('close', function () { | webview.addEventListener('close', function () { | ||||||
|   webview.src = 'about:blank' |   webview.src = 'about:blank'; | ||||||
| }) | }); | ||||||
| 
 | 
 | ||||||
| // In embedder page.
 | // In embedder page.
 | ||||||
| webview.addEventListener('ipc-message', function (event) { | webview.addEventListener('ipc-message', function (event) { | ||||||
|   console.log(event.channel) // Prints "pong"
 |   console.log(event.channel); // Prints "pong"
 | ||||||
| }) | }); | ||||||
| webview.send('ping') | webview.send('ping'); | ||||||
| webview.capturePage().then(image => { console.log(image) }) | webview.capturePage().then(image => { console.log(image); }); | ||||||
| 
 | 
 | ||||||
| { | const opened = webview.isDevToolsOpened(); | ||||||
|   const opened: boolean = webview.isDevToolsOpened() | console.log('isDevToolsOpened', opened); | ||||||
|   const focused: boolean = webview.isDevToolsFocused() | 
 | ||||||
| } | const focused = webview.isDevToolsFocused(); | ||||||
|  | console.log('isDevToolsFocused', focused); | ||||||
| 
 | 
 | ||||||
| // In guest page.
 | // In guest page.
 | ||||||
| ipcRenderer.on('ping', function () { | ipcRenderer.on('ping', function () { | ||||||
|   ipcRenderer.sendToHost('pong') |   ipcRenderer.sendToHost('pong'); | ||||||
| }) | }); | ||||||
|  |  | ||||||
|  | @ -1,18 +1,18 @@ | ||||||
| const path = require('path') | const path = require('path'); | ||||||
| const childProcess = require('child_process') | const childProcess = require('child_process'); | ||||||
| 
 | 
 | ||||||
| const typeCheck = () => { | const typeCheck = () => { | ||||||
|   const tscExec = path.resolve(require.resolve('typescript'), '../../bin/tsc') |   const tscExec = path.resolve(require.resolve('typescript'), '../../bin/tsc'); | ||||||
|   const tscChild = childProcess.spawn(process.execPath, [tscExec, '--project', './ts-smoke/tsconfig.json'], { |   const tscChild = childProcess.spawn(process.execPath, [tscExec, '--project', './ts-smoke/tsconfig.json'], { | ||||||
|     cwd: path.resolve(__dirname, '../') |     cwd: path.resolve(__dirname, '../') | ||||||
|   }) |   }); | ||||||
|   tscChild.stdout.on('data', d => console.log(d.toString())) |   tscChild.stdout.on('data', d => console.log(d.toString())); | ||||||
|   tscChild.stderr.on('data', d => console.error(d.toString())) |   tscChild.stderr.on('data', d => console.error(d.toString())); | ||||||
|   tscChild.on('exit', (tscStatus) => { |   tscChild.on('exit', (tscStatus) => { | ||||||
|     if (tscStatus !== 0) { |     if (tscStatus !== 0) { | ||||||
|       process.exit(tscStatus) |       process.exit(tscStatus); | ||||||
|     } |     } | ||||||
|   }) |   }); | ||||||
| } | }; | ||||||
| 
 | 
 | ||||||
| typeCheck() | typeCheck(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Milan Burda
				Milan Burda