1 | |||
2 | /* TODO: make it work in Travis CI |
||
3 | ------------------------------------------------------------------------ */ |
||
4 | |||
5 | const selenium = require ('selenium-webdriver/testing') |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
6 | |||
7 | /* ------------------------------------------------------------------------ */ |
||
8 | |||
9 | selenium.describe ('Chrome test', (done) => { |
||
10 | |||
11 | const webdriver = require ('selenium-webdriver') |
||
12 | , path = require ('path') |
||
13 | , fs = require ('fs') |
||
14 | , memFS = new (require ('memory-fs')) () |
||
15 | , it = selenium.it |
||
16 | , webpack = require ('webpack') |
||
17 | , logging = require ('selenium-webdriver/lib/logging') |
||
18 | |||
19 | let driver |
||
20 | |||
21 | /* Prepare ChromeDriver (with CORS disabled and log interception enabled) */ |
||
22 | |||
23 | selenium.before (() => driver = |
||
24 | new webdriver |
||
25 | .Builder () |
||
26 | .withCapabilities ( |
||
27 | webdriver.Capabilities |
||
28 | .chrome () |
||
29 | .setLoggingPrefs (new logging.Preferences ().setLevel (logging.Type.BROWSER, logging.Level.ALL)) |
||
30 | .set ('chromeOptions', { |
||
31 | 'args': ['--disable-web-security'] })) |
||
32 | .build ()) |
||
33 | |||
34 | selenium.after (() => driver.quit ()) |
||
35 | |||
36 | it ('works', async () => { |
||
37 | |||
38 | /* Compile get-source */ |
||
39 | |||
40 | const compiledScript = await (new Promise (resolve => { Object.assign (webpack ({ |
||
41 | |||
42 | entry: './test/files/get-source.webpack.entry.js', |
||
43 | output: { path: '/', filename: 'get-source.webpack.compiled.js' }, |
||
44 | plugins: [ new webpack.IgnorePlugin(/^fs$/) ] |
||
45 | |||
46 | }), { outputFileSystem: memFS }).run ((err, stats) => { |
||
47 | |||
48 | if (err) throw err |
||
49 | |||
50 | resolve (memFS.readFileSync ('/get-source.webpack.compiled.js').toString ('utf-8')) |
||
51 | }) |
||
52 | })) |
||
53 | |||
54 | /* Inject it into Chrome */ |
||
55 | |||
56 | driver.get ('file://' + path.resolve ('./test/files/test.html')) |
||
57 | driver.executeScript (compiledScript) |
||
58 | |||
59 | /* Execute test */ |
||
60 | |||
61 | const exec = fn => driver.executeScript (`(${fn.toString ()})()`) |
||
62 | |||
63 | try { |
||
64 | |||
65 | await exec (function () { |
||
66 | |||
67 | path.relativeToFile ('http://foo.com/scripts/bar.js', '../bar.js.map') |
||
68 | .should.equal ('http://foo.com/bar.js.map') |
||
69 | |||
70 | path.relativeToFile ('http://foo.com/scripts/bar.js', 'http://bar.js.map') |
||
71 | .should.equal ('http://bar.js.map') |
||
72 | |||
73 | path.relativeToFile ('http://foo.com/scripts/bar.js', '/bar.js.map') |
||
74 | .should.equal ('file:///bar.js.map') |
||
75 | |||
76 | var loc = getSource ('../original.uglified.beautified.js').resolve ({ line: 2, column: 4 }) |
||
77 | |||
78 | loc.line.should.equal (4) |
||
79 | loc.column.should.equal (2) |
||
80 | loc.sourceFile.path.should.contain ('test/files/original.js') |
||
81 | loc.sourceLine.should.equal ('\treturn \'hello world\' }') |
||
82 | }) |
||
83 | |||
84 | } catch (e) { throw e } finally { |
||
85 | |||
86 | driver.manage ().logs ().get (logging.Type.BROWSER).then (entries => { |
||
87 | entries.forEach (entry => { |
||
88 | console.log('[BROWSER] [%s] %s', entry.level.name, entry.message); |
||
89 | }) |
||
90 | }) |
||
91 | } |
||
92 | }) |
||
93 | }) |
||
94 | |||
95 | /* ------------------------------------------------------------------------ */ |
||
96 |