From 4e87195739f2a5d9a05451b48773c8afdc680765 Mon Sep 17 00:00:00 2001 From: akiyamn Date: Sun, 24 Sep 2023 23:22:21 +1000 Subject: Initial commit (by create-cloudflare CLI) --- .../test/files/get-source.webpack.entry.js | 3 + .../original.babeled.with.inline.sourcemap.js | 9 + node_modules/get-source/test/files/original.js | 4 + .../test/files/original.uglified.beautified.js | 4 + .../test/files/original.uglified.beautified.js.map | 1 + .../get-source/test/files/original.uglified.js | 2 + .../get-source/test/files/original.uglified.js.map | 1 + .../test/files/original.uglified.with.sources.js | 2 + .../files/original.uglified.with.sources.js.map | 1 + node_modules/get-source/test/files/test.html | 1 + node_modules/get-source/test/test.browser.js | 98 +++++++++ node_modules/get-source/test/test.node.js | 222 +++++++++++++++++++++ node_modules/get-source/test/test.path.js | 56 ++++++ 13 files changed, 404 insertions(+) create mode 100644 node_modules/get-source/test/files/get-source.webpack.entry.js create mode 100644 node_modules/get-source/test/files/original.babeled.with.inline.sourcemap.js create mode 100644 node_modules/get-source/test/files/original.js create mode 100644 node_modules/get-source/test/files/original.uglified.beautified.js create mode 100644 node_modules/get-source/test/files/original.uglified.beautified.js.map create mode 100644 node_modules/get-source/test/files/original.uglified.js create mode 100644 node_modules/get-source/test/files/original.uglified.js.map create mode 100644 node_modules/get-source/test/files/original.uglified.with.sources.js create mode 100644 node_modules/get-source/test/files/original.uglified.with.sources.js.map create mode 100644 node_modules/get-source/test/files/test.html create mode 100644 node_modules/get-source/test/test.browser.js create mode 100644 node_modules/get-source/test/test.node.js create mode 100644 node_modules/get-source/test/test.path.js (limited to 'node_modules/get-source/test') diff --git a/node_modules/get-source/test/files/get-source.webpack.entry.js b/node_modules/get-source/test/files/get-source.webpack.entry.js new file mode 100644 index 0000000..aa676cd --- /dev/null +++ b/node_modules/get-source/test/files/get-source.webpack.entry.js @@ -0,0 +1,3 @@ +require ('chai').should () +window.path = require ('../../impl/path') +window.getSource = require ('../../get-source') \ No newline at end of file diff --git a/node_modules/get-source/test/files/original.babeled.with.inline.sourcemap.js b/node_modules/get-source/test/files/original.babeled.with.inline.sourcemap.js new file mode 100644 index 0000000..8ed6136 --- /dev/null +++ b/node_modules/get-source/test/files/original.babeled.with.inline.sourcemap.js @@ -0,0 +1,9 @@ +'use strict'; + +/* Dummy javascript file */ + +function hello() { + return 'hello world'; +} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUE7O0FBRUEsU0FBUyxLQUFULEdBQWtCO0FBQ2pCLFFBQU8sYUFBUDtBQUFzQiIsImZpbGUiOiJvcmlnaW5hbC5iYWJlbGVkLndpdGguaW5saW5lLnNvdXJjZW1hcC5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8qXHREdW1teSBqYXZhc2NyaXB0IGZpbGVcdCovXG5cbmZ1bmN0aW9uIGhlbGxvICgpIHtcblx0cmV0dXJuICdoZWxsbyB3b3JsZCcgfSJdfQ== \ No newline at end of file diff --git a/node_modules/get-source/test/files/original.js b/node_modules/get-source/test/files/original.js new file mode 100644 index 0000000..f91aae4 --- /dev/null +++ b/node_modules/get-source/test/files/original.js @@ -0,0 +1,4 @@ +/* Dummy javascript file */ + +function hello () { + return 'hello world' } \ No newline at end of file diff --git a/node_modules/get-source/test/files/original.uglified.beautified.js b/node_modules/get-source/test/files/original.uglified.beautified.js new file mode 100644 index 0000000..b92406c --- /dev/null +++ b/node_modules/get-source/test/files/original.uglified.beautified.js @@ -0,0 +1,4 @@ +function hello() { + return "hello world"; +} +//# sourceMappingURL=original.uglified.beautified.js.map diff --git a/node_modules/get-source/test/files/original.uglified.beautified.js.map b/node_modules/get-source/test/files/original.uglified.beautified.js.map new file mode 100644 index 0000000..8750ef6 --- /dev/null +++ b/node_modules/get-source/test/files/original.uglified.beautified.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["original.uglified.js"],"names":["hello"],"mappings":"AAAA,SAASA;IAAQ,OAAM"} \ No newline at end of file diff --git a/node_modules/get-source/test/files/original.uglified.js b/node_modules/get-source/test/files/original.uglified.js new file mode 100644 index 0000000..14b93ce --- /dev/null +++ b/node_modules/get-source/test/files/original.uglified.js @@ -0,0 +1,2 @@ +function hello(){return"hello world"} +//# sourceMappingURL=original.uglified.js.map diff --git a/node_modules/get-source/test/files/original.uglified.js.map b/node_modules/get-source/test/files/original.uglified.js.map new file mode 100644 index 0000000..1018216 --- /dev/null +++ b/node_modules/get-source/test/files/original.uglified.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["original.js"],"names":["hello"],"mappings":"AAEA,QAASA,SACR,MAAO"} \ No newline at end of file diff --git a/node_modules/get-source/test/files/original.uglified.with.sources.js b/node_modules/get-source/test/files/original.uglified.with.sources.js new file mode 100644 index 0000000..1b9f726 --- /dev/null +++ b/node_modules/get-source/test/files/original.uglified.with.sources.js @@ -0,0 +1,2 @@ +function hello(){return"hello world"} +//# sourceMappingURL=original.uglified.with.sources.js.map diff --git a/node_modules/get-source/test/files/original.uglified.with.sources.js.map b/node_modules/get-source/test/files/original.uglified.with.sources.js.map new file mode 100644 index 0000000..77923be --- /dev/null +++ b/node_modules/get-source/test/files/original.uglified.with.sources.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["## embedded ##"],"names":["hello"],"mappings":"AAEA,QAASA,SACR,MAAO","sourcesContent":["/*\tDummy javascript file\t*/\n\nfunction hello () {\n\treturn 'hello world' }"]} \ No newline at end of file diff --git a/node_modules/get-source/test/files/test.html b/node_modules/get-source/test/files/test.html new file mode 100644 index 0000000..6c70bcf --- /dev/null +++ b/node_modules/get-source/test/files/test.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/node_modules/get-source/test/test.browser.js b/node_modules/get-source/test/test.browser.js new file mode 100644 index 0000000..ed7b523 --- /dev/null +++ b/node_modules/get-source/test/test.browser.js @@ -0,0 +1,98 @@ + +/* TODO: make it work in Travis CI + ------------------------------------------------------------------------ */ + +const selenium = require ('selenium-webdriver/testing') + +/* ------------------------------------------------------------------------ */ + +selenium.describe ('Chrome test', (done) => { + + const webdriver = require ('selenium-webdriver') + , path = require ('path') + , fs = require ('fs') + , memFS = new (require ('memory-fs')) () + , it = selenium.it + , webpack = require ('webpack') + , logging = require ('selenium-webdriver/lib/logging') + + let driver + +/* Prepare ChromeDriver (with CORS disabled and log interception enabled) */ + + selenium.before (() => driver = + new webdriver + .Builder () + .withCapabilities ( + webdriver.Capabilities + .chrome () + .setLoggingPrefs (new logging.Preferences ().setLevel (logging.Type.BROWSER, logging.Level.ALL)) + .set ('chromeOptions', { + 'args': ['--disable-web-security'] })) + .build ()) + + selenium.after (() => driver.quit ()) + + it ('works', async () => { + + /* Compile get-source */ + + const compiledScript = await (new Promise (resolve => { Object.assign (webpack ({ + + entry: './test/files/get-source.webpack.entry.js', + output: { path: '/', filename: 'get-source.webpack.compiled.js' }, + plugins: [ new webpack.IgnorePlugin(/^fs$/) ] + + }), { outputFileSystem: memFS }).run ((err, stats) => { + + if (err) throw err + + resolve (memFS.readFileSync ('/get-source.webpack.compiled.js').toString ('utf-8')) + }) + })) + + /* Inject it into Chrome */ + + driver.get ('file://' + path.resolve ('./test/files/test.html')) + driver.executeScript (compiledScript) + + /* Execute test */ + + const exec = fn => driver.executeScript (`(${fn.toString ()})()`) + + try { + + await exec (function () { + + path.relativeToFile ('http://foo.com/scripts/bar.js', '../bar.js.map') + .should.equal ('http://foo.com/bar.js.map') + + path.relativeToFile ('http://foo.com/scripts/bar.js', 'http://bar.js.map') + .should.equal ('http://bar.js.map') + + path.relativeToFile ('http://foo.com/scripts/bar.js', '/bar.js.map') + .should.equal ('file:///bar.js.map') + + path.relativeToFile ('http://foo.com/scripts/bar.js', '//bar.com/bar.js.map') + .should.equal ('http://bar.com/bar.js.map') + + var loc = getSource ('../original.uglified.beautified.js').resolve ({ line: 2, column: 4 }) + + loc.line.should.equal (4) + loc.column.should.equal (2) + loc.sourceFile.path.should.contain ('test/files/original.js') + loc.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + + } catch (e) { throw e } finally { + + driver.manage ().logs ().get (logging.Type.BROWSER).then (entries => { + entries.forEach (entry => { + console.log('[BROWSER] [%s] %s', entry.level.name, entry.message); + }) + }) + } + }) +}) + +/* ------------------------------------------------------------------------ */ diff --git a/node_modules/get-source/test/test.node.js b/node_modules/get-source/test/test.node.js new file mode 100644 index 0000000..d546ff6 --- /dev/null +++ b/node_modules/get-source/test/test.node.js @@ -0,0 +1,222 @@ +"use strict"; + +/* NOTE: I've used supervisor to auto-restart mocha, because mocha --watch + didn't work for selenium tests (not reloading them)... + ------------------------------------------------------------------ */ + +require ('chai').should () + +/* ------------------------------------------------------------------------ */ + +describe ('get-source', () => { + + const getSource = require ('../get-source'), + fs = require ('fs'), + path = require ('path') + + it ('cache sanity check', () => { + + getSource ('./get-source.js').should.equal (getSource ('./get-source.js')) + getSource ('./get-source.js').should.not.equal (getSource ('./package.json')) + }) + + it ('reads sources (not sourcemapped)', () => { + + const original = getSource ('./test/files/original.js') + + original.path.should.equal (path.resolve ('./test/files/original.js')) // resolves input paths + original.text.should.equal (fs.readFileSync ('./test/files/original.js', { encoding: 'utf-8' })) + original.lines.should.deep.equal ([ + '/*\tDummy javascript file\t*/', + '', + 'function hello () {', + '\treturn \'hello world\' }' + ]) + + const resolved = original.resolve ({ line: 4, column: 1 }) + + resolved.line.should.equal (4) + resolved.column.should.equal (1) + resolved.sourceFile.should.equal (original) + resolved.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + + it ('reads sources (sourcemapped, with external links)', () => { + + const uglified = getSource ('./test/files/original.uglified.js') + + uglified.path.should.equal (path.resolve ('./test/files/original.uglified.js')) + uglified.lines.should.deep.equal ([ + 'function hello(){return"hello world"}', + '//# sourceMappingURL=original.uglified.js.map', + '' + ]) + + // uglified.sourceMap.should.not.equal (undefined) + // uglified.sourceMap.should.equal (uglified.sourceMap) // memoization should work + + const resolved = uglified.resolve ({ line: 1, column: 18 }) // should be tolerant to column omission + + resolved.line.should.equal (4) + resolved.column.should.equal (2) + resolved.sourceFile.should.equal (getSource ('./test/files/original.js')) + resolved.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + + it ('reads sources (sourcemapped, with external links) — ASYNC', () => { + + const uglified = getSource.async ('./test/files/original.uglified.js') + + return uglified.then (uglified => { + + uglified.path.should.equal (path.resolve ('./test/files/original.uglified.js')) + uglified.lines.should.deep.equal ([ + 'function hello(){return"hello world"}', + '//# sourceMappingURL=original.uglified.js.map', + '' + ]) + + // uglified.sourceMap.should.not.equal (undefined) + // uglified.sourceMap.should.equal (uglified.sourceMap) // memoization should work + + return uglified.resolve ({ line: 1, column: 18 }).then (resolved => { + + return getSource.async ('./test/files/original.js').then (originalFile => { + resolved.line.should.equal (4) + resolved.column.should.equal (2) + resolved.sourceFile.should.equal (originalFile) + resolved.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + }) + }) + }) + + it ('reads sources (sourcemapped, with embedded sources)', () => { + + const uglified = getSource ('./test/files/original.uglified.with.sources.js') + + uglified.path.should.equal (path.resolve ('./test/files/original.uglified.with.sources.js')) + uglified.lines.should.deep.equal ([ + 'function hello(){return"hello world"}', + '//# sourceMappingURL=original.uglified.with.sources.js.map', + '' + ]) + + // uglified.sourceMap.should.not.equal (undefined) + + const resolved = uglified.resolve ({ line: 1, column: 18 }) + + resolved.line.should.equal (4) + resolved.column.should.equal (2) + resolved.sourceFile.path.should.equal (path.resolve ('./test/files') + '/## embedded ##') // I've changed the filename manually, by editing .map file + resolved.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + + it ('reads sources (sourcemapped, with inline base64 sourcemaps)', () => { + + const babeled = getSource ('./test/files/original.babeled.with.inline.sourcemap.js') + + // babeled.sourceMap.should.not.equal (undefined) + // babeled.sourceMap.file.path.should.equal (babeled.path) + + const resolved = babeled.resolve ({ line: 6, column: 1 }) + + resolved.line.should.equal (4) + resolved.column.should.equal (2) + resolved.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + + it ('supports even CHAINED sourcemaps!', () => { + + /* original.js → original.uglified.js → original.uglified.beautified.js */ + + const beautified = getSource ('./test/files/original.uglified.beautified.js') + + beautified.path.should.equal (path.resolve ('./test/files/original.uglified.beautified.js')) + beautified.text.should.equal (fs.readFileSync ('./test/files/original.uglified.beautified.js', { encoding: 'utf-8' })) + + // beautified.sourceMap.should.not.equal (undefined) + + const resolved = beautified.resolve ({ line: 2, column: 4 }) + + resolved.line.should.equal (4) + resolved.column.should.equal (2) + resolved.sourceFile.path.should.equal (path.resolve ('./test/files/original.js')) + resolved.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + + it ('adheres to async interface', () => { + + return getSource.async ('./get-source.js').then (result => { + + ;(result.resolve ({ line: 1, column: 0 }) instanceof Promise).should.equal (true) + }) + }) + + it ('supports even CHAINED sourcemaps! — ASYNC', () => { + + /* original.js → original.uglified.js → original.uglified.beautified.js */ + + return getSource.async ('./test/files/original.uglified.beautified.js').then (beautified => { + + beautified.text.should.equal (fs.readFileSync ('./test/files/original.uglified.beautified.js', { encoding: 'utf-8' })) + beautified.path.should.equal (path.resolve ('./test/files/original.uglified.beautified.js')) + + return beautified.resolve ({ line: 2, column: 4 }).then (resolved => { + + resolved.line.should.equal (4) + resolved.column.should.equal (2) + resolved.sourceFile.path.should.equal (path.resolve ('./test/files/original.js')) + resolved.sourceLine.should.equal ('\treturn \'hello world\' }') + }) + }) + }) + + it ('does some error handling', () => { + + const nonsense = getSource ('abyrvalg') + + nonsense.text.should.equal ('') + nonsense.error.should.be.an.instanceof (Error) + + const resolved = nonsense.resolve ({ line: 5, column: 0 }) + + resolved.error.should.equal (nonsense.error) + resolved.sourceLine.should.equal ('') + resolved.sourceFile.path.should.equal ('abyrvalg') + }) + + it ('does some error handling - ASYNC', () => { + + return getSource.async ('abyrvalg').then (x => { console.log (x) }).catch (error => { + error.should.be.an.instanceof (Error) + }) + }) + + it ('allows absolute paths', () => { + + getSource (require ('path').resolve ('./get-source.js')).should.equal (getSource ('./get-source.js')) + }) + + it ('caching works', () => { + + const files = + [ './get-source.js', + './package.json', + './test/files/original.js', + './test/files/original.uglified.js', + './test/files/original.uglified.js.map', + './test/files/original.uglified.with.sources.js', + './test/files/original.uglified.with.sources.js.map', + './test/files/original.babeled.with.inline.sourcemap.js', + './test/files/original.uglified.beautified.js', + './test/files/original.uglified.beautified.js.map', + './abyrvalg' ] + + Object.keys (getSource.getCache ()).should.deep.equal (files.map (x => path.resolve (x))) + + getSource.resetCache () + + Object.keys (getSource.getCache ()).length.should.equal (0) + }) +}) \ No newline at end of file diff --git a/node_modules/get-source/test/test.path.js b/node_modules/get-source/test/test.path.js new file mode 100644 index 0000000..610ac2f --- /dev/null +++ b/node_modules/get-source/test/test.path.js @@ -0,0 +1,56 @@ +"use strict"; + +/* ------------------------------------------------------------------------ */ + +require ('chai').should () + +/* ------------------------------------------------------------------------ */ + +describe ('path', () => { + + const path = require ('../impl/path') + + it ('resolves', () => { + + path.resolve ('./foo/bar/../qux').should.equal (process.cwd () + '/foo/qux') + }) + + it ('normalizes', () => { + + path.normalize ('./foo/./bar/.././.././qux.map./').should.equal ('qux.map./') + + path.normalize ('/a/b').should.equal ('/a/b') + path.normalize ('http://foo/bar').should.equal ('http://foo/bar') + }) + + it ('computes relative location', () => { + + path.relativeToFile ('/foo/bar.js', './qux.map') + .should.equal ('/foo/qux.map') + + path.relativeToFile ('/foo/bar/baz.js', './../.././qux.map') + .should.equal ('/qux.map') + + path.relativeToFile ('/foo/bar', 'webpack:something') + .should.equal ('webpack:something') + + path.relativeToFile ('/foo/bar', 'web/pack:something') + .should.equal ('/foo/web/pack:something') + }) + + it ('works with data URIs', () => { + + path.relativeToFile ('/foo/bar.js', 'data:application/json;charset=utf-8;base64,eyJ2ZXJza==') + .should.equal ( 'data:application/json;charset=utf-8;base64,eyJ2ZXJza==') + + path.relativeToFile ('data:application/json;charset=utf-8;base64,eyJ2ZXJza==', 'foo.js') + .should.equal ( 'foo.js') + }) + + it ('implements isURL', () => { + + path.isURL ('foo.js').should.equal (false) + path.isURL ('/foo/bar.js').should.equal (false) + path.isURL ('https://google.com').should.equal (true) + }) +}) \ No newline at end of file -- cgit v1.2.3