js-build-tools 6.5.0 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -674
- package/README.md +762 -692
- package/babel.config.js +28 -28
- package/dist/build.js +75 -75
- package/dist/bundle.js +19 -19
- package/dist/bundleMinify.js +7 -7
- package/dist/compileReadme.js +4 -4
- package/dist/copyFiles.js +17 -17
- package/dist/copyFonts.js +4 -4
- package/dist/default.js +5 -5
- package/dist/dist.js +4 -4
- package/dist/distMinify.js +4 -4
- package/dist/docs.js +7 -7
- package/dist/images.js +4 -4
- package/dist/jsdocDocs.js +6 -6
- package/dist/lint.js +16 -16
- package/dist/partials/addToReadme.js +9 -9
- package/dist/partials/beginWatcher.js +4 -4
- package/dist/partials/clean.js +5 -5
- package/dist/partials/copyFor.js +9 -9
- package/dist/partials/distFor.js +6 -6
- package/dist/partials/distForSrc.js +5 -5
- package/dist/partials/distSeries.js +7 -7
- package/dist/partials/imagesFor.js +93 -56
- package/dist/partials/jsdocDocsFor.js +46 -46
- package/dist/partials/lintSource.js +51 -51
- package/dist/partials/loadPeer.js +99 -99
- package/dist/partials/loadPlaywright.js +14 -14
- package/dist/partials/minifyFor.js +20 -20
- package/dist/partials/neostandardLint.js +175 -175
- package/dist/partials/readmeTemplate.js +4 -4
- package/dist/partials/removeDirectory.js +11 -11
- package/dist/partials/resolveDocsMethod.js +6 -6
- package/dist/partials/runOnChange.js +31 -31
- package/dist/partials/sassFor.js +6 -6
- package/dist/partials/serveStatic.js +9 -9
- package/dist/partials/tsFor.js +32 -32
- package/dist/partials/typeDocsFor.js +57 -51
- package/dist/partials.js +176 -176
- package/dist/sourceLint.js +18 -18
- package/dist/test-helpers/isolateGulpCache.js +24 -24
- package/dist/test-helpers/setUp.js +4 -4
- package/dist/testFull.js +5 -5
- package/dist/testQuick.js +5 -5
- package/dist/typeDocs.js +5 -5
- package/dist/typeScript.js +4 -4
- package/dist/utilities/convertMjsFilesForDocs.js +12 -12
- package/dist/utilities/dotGet.js +54 -54
- package/dist/utilities/dotNotate.js +79 -79
- package/dist/utilities/dotSet.js +45 -45
- package/dist/utilities/esmNamedExportsToCjs.js +15 -15
- package/dist/utilities/getBundleConfigs.js +9 -9
- package/dist/utilities/isObject.js +6 -6
- package/dist/utilities/strAfter.js +7 -7
- package/dist/utilities/strBefore.js +7 -7
- package/dist/watchFull.js +4 -4
- package/dist/watchTest.js +4 -4
- package/functions/build.mjs +72 -72
- package/functions/build.test.mjs +763 -759
- package/functions/bundle.mjs +44 -44
- package/functions/bundle.test.mjs +219 -219
- package/functions/bundleMinify.mjs +16 -16
- package/functions/bundleMinify.test.mjs +37 -37
- package/functions/compileReadme.mjs +9 -9
- package/functions/compileReadme.test.mjs +18 -18
- package/functions/copyFiles.mjs +32 -32
- package/functions/copyFiles.test.mjs +78 -78
- package/functions/copyFonts.mjs +9 -9
- package/functions/copyFonts.test.mjs +32 -32
- package/functions/default.mjs +12 -12
- package/functions/default.test.mjs +33 -33
- package/functions/dist.mjs +8 -8
- package/functions/dist.test.mjs +44 -44
- package/functions/distMinify.mjs +9 -9
- package/functions/distMinify.test.mjs +15 -15
- package/functions/docs.mjs +13 -13
- package/functions/docs.test.mjs +45 -45
- package/functions/gulpConfigEntries.test.mjs +23 -23
- package/functions/images.mjs +8 -8
- package/functions/images.test.mjs +142 -142
- package/functions/jsdocDocs.mjs +10 -10
- package/functions/jsdocEsmExports.test.mjs +24 -24
- package/functions/lint.mjs +9 -9
- package/functions/partials/addToReadme.mjs +25 -25
- package/functions/partials/addToReadme.test.mjs +34 -34
- package/functions/partials/beginWatcher.mjs +9 -9
- package/functions/partials/beginWatcher.test.mjs +19 -19
- package/functions/partials/clean.mjs +13 -13
- package/functions/partials/clean.test.mjs +22 -22
- package/functions/partials/copyFor.mjs +15 -15
- package/functions/partials/copyFor.test.mjs +53 -53
- package/functions/partials/distFor.mjs +22 -22
- package/functions/partials/distFor.test.mjs +195 -195
- package/functions/partials/distForSrc.mjs +11 -11
- package/functions/partials/distForSrc.test.mjs +18 -18
- package/functions/partials/distSeries.mjs +21 -21
- package/functions/partials/distSeries.test.mjs +34 -34
- package/functions/partials/imagesFor.mjs +83 -50
- package/functions/partials/imagesFor.test.mjs +287 -229
- package/functions/partials/jsdocDocsFor.mjs +163 -152
- package/functions/partials/jsdocDocsFor.test.mjs +182 -152
- package/functions/partials/lintSource.mjs +41 -41
- package/functions/partials/loadPeer.mjs +76 -76
- package/functions/partials/loadPeer.test.mjs +58 -58
- package/functions/partials/loadPlaywright.mjs +23 -23
- package/functions/partials/loadPlaywright.test.mjs +70 -70
- package/functions/partials/minifyFor.mjs +15 -15
- package/functions/partials/minifyFor.test.mjs +49 -49
- package/functions/partials/neostandardLint.mjs +142 -142
- package/functions/partials/neostandardLint.test.mjs +131 -131
- package/functions/partials/readmeTemplate.mjs +12 -12
- package/functions/partials/readmeTemplate.test.mjs +34 -34
- package/functions/partials/removeDirectory.mjs +34 -34
- package/functions/partials/removeDirectory.test.mjs +72 -72
- package/functions/partials/resolveDocsMethod.mjs +10 -10
- package/functions/partials/resolveDocsMethod.test.mjs +33 -33
- package/functions/partials/runOnChange.mjs +54 -54
- package/functions/partials/runOnChange.test.mjs +95 -95
- package/functions/partials/sassFor.mjs +25 -25
- package/functions/partials/sassFor.test.mjs +81 -81
- package/functions/partials/serveStatic.mjs +47 -47
- package/functions/partials/serveStatic.test.mjs +71 -71
- package/functions/partials/tsFor.mjs +92 -92
- package/functions/partials/tsFor.test.mjs +88 -88
- package/functions/partials/typeDocsFor.mjs +231 -227
- package/functions/partials/typeDocsFor.test.mjs +263 -252
- package/functions/partials.mjs +31 -31
- package/functions/partials.test.mjs +7 -7
- package/functions/sass.mjs +4 -4
- package/functions/sass.test.mjs +31 -31
- package/functions/sourceLint.mjs +13 -13
- package/functions/sourceLint.test.mjs +166 -166
- package/functions/test-helpers/isolateGulpCache.mjs +16 -16
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -40
- package/functions/test-helpers/setUp.mjs +100 -100
- package/functions/test-helpers/setUp.test.mjs +19 -19
- package/functions/testFull.mjs +17 -17
- package/functions/testFull.test.mjs +17 -17
- package/functions/testHelpers.mjs +10 -10
- package/functions/testHelpers.test.mjs +7 -7
- package/functions/testQuick.mjs +17 -17
- package/functions/testQuick.test.mjs +17 -17
- package/functions/typeDocs.mjs +9 -9
- package/functions/typeDocs.test.mjs +11 -11
- package/functions/typeScript.mjs +8 -8
- package/functions/typeScript.test.mjs +11 -11
- package/functions/utilities/convertMjsFilesForDocs.mjs +34 -34
- package/functions/utilities/convertMjsFilesForDocs.test.mjs +58 -58
- package/functions/utilities/dotGet.mjs +49 -49
- package/functions/utilities/dotNotate.mjs +73 -73
- package/functions/utilities/dotNotate.test.mjs +41 -41
- package/functions/utilities/dotSet.mjs +40 -40
- package/functions/utilities/esmNamedExportsToCjs.mjs +30 -30
- package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -47
- package/functions/utilities/getBundleConfigs.mjs +30 -30
- package/functions/utilities/isObject.mjs +8 -8
- package/functions/utilities/strAfter.mjs +12 -12
- package/functions/utilities/strBefore.mjs +12 -12
- package/functions/watchFull.mjs +9 -9
- package/functions/watchFull.test.mjs +41 -41
- package/functions/watchTest.mjs +10 -10
- package/functions/watchTest.test.mjs +49 -49
- package/gulp.config.js +4 -4
- package/gulp.config.mjs +344 -327
- package/gulpfile.base.js +51 -51
- package/gulpfile.base.mjs +29 -29
- package/jsdoc.base.js +16 -16
- package/jsdoc.esmExports.js +17 -17
- package/package.json +146 -145
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import * as setUp from '../test-helpers/setUp.mjs'
|
|
4
|
-
import { importModule, importPeer, requirePeer } from './loadPeer.mjs'
|
|
5
|
-
|
|
6
|
-
setUp.setDefaults('test-load-peer')
|
|
7
|
-
|
|
8
|
-
const options = { task: 'example', installHint: 'Install it with: npm install --save-dev fake-peer' }
|
|
9
|
-
|
|
10
|
-
// A project with its own node_modules, so the packages are found from the project rather than from this package
|
|
11
|
-
const projectWith = (name, files) => {
|
|
12
|
-
const project = path.resolve('test-load-peer/project')
|
|
13
|
-
fs.mkdirSync(`${project}/node_modules/${name}`, { recursive: true })
|
|
14
|
-
fs.writeFileSync(`${project}/package.json`, '{}')
|
|
15
|
-
Object.entries(files).forEach(([file, contents]) => fs.writeFileSync(`${project}/node_modules/${name}/${file}`, contents))
|
|
16
|
-
return project
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
beforeEach(setUp.beforeEach)
|
|
20
|
-
afterEach(setUp.afterEach)
|
|
21
|
-
|
|
22
|
-
describe('requirePeer', () => {
|
|
23
|
-
test('loads the package from the project being built', () => {
|
|
24
|
-
const project = projectWith('fake-peer', { 'package.json': '{"name":"fake-peer","main":"index.js"}', 'index.js': 'module.exports = { found: true }' })
|
|
25
|
-
expect(requirePeer('fake-peer', { ...options, projectPath: project })).toEqual({ found: true })
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('explains how to install the package when the project does not have it', () => {
|
|
29
|
-
expect(() => requirePeer('fake-peer', { ...options, projectPath: '/' })).toThrow(
|
|
30
|
-
'The example task needs the optional peer dependency fake-peer, which is not installed. Install it with: npm install --save-dev fake-peer'
|
|
31
|
-
)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('does not hide other errors, and explains a package which is ESM-only when it has a message for that', () => {
|
|
35
|
-
const project = projectWith('broken-peer', { 'package.json': '{"name":"broken-peer","main":"index.js"}', 'index.js': 'throw new Error("boom")' })
|
|
36
|
-
expect(() => requirePeer('broken-peer', { ...options, projectPath: project })).toThrow('boom')
|
|
37
|
-
// A missing dependency of the peer is not the peer being missing
|
|
38
|
-
const inner = projectWith('inner-peer', { 'package.json': '{"name":"inner-peer","main":"index.js"}', 'index.js': 'require("something-else-missing")' })
|
|
39
|
-
expect(() => requirePeer('inner-peer', { ...options, projectPath: inner })).toThrow(/something-else-missing/)
|
|
40
|
-
expect(() => requirePeer('inner-peer', { ...options, projectPath: inner })).not.toThrow(/optional peer dependency/)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('importPeer', () => {
|
|
45
|
-
test('explains how to install the package when the project does not have it', async () => {
|
|
46
|
-
await expect(importPeer('fake-peer', { ...options, projectPath: '/' })).rejects.toThrow(
|
|
47
|
-
/needs the optional peer dependency fake-peer, which is not installed. Install it with/
|
|
48
|
-
)
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
describe('importModule', () => {
|
|
53
|
-
// The real import() cannot run under this project's CommonJS-transform-based Jest setup (see tsFor.mjs), so the
|
|
54
|
-
// loaders are checked by running the tasks for real, see the pull request.
|
|
55
|
-
test('is a function', () => {
|
|
56
|
-
expect(importModule).toBeInstanceOf(Function)
|
|
57
|
-
})
|
|
58
|
-
})
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import * as setUp from '../test-helpers/setUp.mjs'
|
|
4
|
+
import { importModule, importPeer, requirePeer } from './loadPeer.mjs'
|
|
5
|
+
|
|
6
|
+
setUp.setDefaults('test-load-peer')
|
|
7
|
+
|
|
8
|
+
const options = { task: 'example', installHint: 'Install it with: npm install --save-dev fake-peer' }
|
|
9
|
+
|
|
10
|
+
// A project with its own node_modules, so the packages are found from the project rather than from this package
|
|
11
|
+
const projectWith = (name, files) => {
|
|
12
|
+
const project = path.resolve('test-load-peer/project')
|
|
13
|
+
fs.mkdirSync(`${project}/node_modules/${name}`, { recursive: true })
|
|
14
|
+
fs.writeFileSync(`${project}/package.json`, '{}')
|
|
15
|
+
Object.entries(files).forEach(([file, contents]) => fs.writeFileSync(`${project}/node_modules/${name}/${file}`, contents))
|
|
16
|
+
return project
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
beforeEach(setUp.beforeEach)
|
|
20
|
+
afterEach(setUp.afterEach)
|
|
21
|
+
|
|
22
|
+
describe('requirePeer', () => {
|
|
23
|
+
test('loads the package from the project being built', () => {
|
|
24
|
+
const project = projectWith('fake-peer', { 'package.json': '{"name":"fake-peer","main":"index.js"}', 'index.js': 'module.exports = { found: true }' })
|
|
25
|
+
expect(requirePeer('fake-peer', { ...options, projectPath: project })).toEqual({ found: true })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('explains how to install the package when the project does not have it', () => {
|
|
29
|
+
expect(() => requirePeer('fake-peer', { ...options, projectPath: '/' })).toThrow(
|
|
30
|
+
'The example task needs the optional peer dependency fake-peer, which is not installed. Install it with: npm install --save-dev fake-peer'
|
|
31
|
+
)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('does not hide other errors, and explains a package which is ESM-only when it has a message for that', () => {
|
|
35
|
+
const project = projectWith('broken-peer', { 'package.json': '{"name":"broken-peer","main":"index.js"}', 'index.js': 'throw new Error("boom")' })
|
|
36
|
+
expect(() => requirePeer('broken-peer', { ...options, projectPath: project })).toThrow('boom')
|
|
37
|
+
// A missing dependency of the peer is not the peer being missing
|
|
38
|
+
const inner = projectWith('inner-peer', { 'package.json': '{"name":"inner-peer","main":"index.js"}', 'index.js': 'require("something-else-missing")' })
|
|
39
|
+
expect(() => requirePeer('inner-peer', { ...options, projectPath: inner })).toThrow(/something-else-missing/)
|
|
40
|
+
expect(() => requirePeer('inner-peer', { ...options, projectPath: inner })).not.toThrow(/optional peer dependency/)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe('importPeer', () => {
|
|
45
|
+
test('explains how to install the package when the project does not have it', async () => {
|
|
46
|
+
await expect(importPeer('fake-peer', { ...options, projectPath: '/' })).rejects.toThrow(
|
|
47
|
+
/needs the optional peer dependency fake-peer, which is not installed. Install it with/
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('importModule', () => {
|
|
53
|
+
// The real import() cannot run under this project's CommonJS-transform-based Jest setup (see tsFor.mjs), so the
|
|
54
|
+
// loaders are checked by running the tasks for real, see the pull request.
|
|
55
|
+
test('is a function', () => {
|
|
56
|
+
expect(importModule).toBeInstanceOf(Function)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { requirePeer } from './loadPeer.mjs'
|
|
2
|
-
|
|
3
|
-
const installHint = 'Install it in your project with: npm install --save-dev playwright'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Find Playwright (headless-browser automation) of the project being built, an optional peer dependency only
|
|
7
|
-
* needed by whatever actually drives a real browser - projects which never do never need it installed.
|
|
8
|
-
* @memberOf module:partials
|
|
9
|
-
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
10
|
-
* @returns {Object} The Playwright module.
|
|
11
|
-
* @throws {Error} With install instructions when playwright is not installed.
|
|
12
|
-
*/
|
|
13
|
-
export const loadPlaywright = (projectPath = process.cwd()) => requirePeer('playwright', { task: 'browser automation', installHint, projectPath })
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Launch a real headless Chromium browser via Playwright. See {@link loadPlaywright}.
|
|
17
|
-
* @memberOf module:partials
|
|
18
|
-
* @param {Function} [load=loadPlaywright] Which Playwright to launch - swappable in tests.
|
|
19
|
-
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
20
|
-
* @returns {Promise<Browser>} The running Playwright browser - close it yourself (browser.close()) once done with it.
|
|
21
|
-
* @throws {Error} With install instructions when playwright is not installed.
|
|
22
|
-
*/
|
|
23
|
-
export const launchBrowser = (load = loadPlaywright, projectPath = process.cwd()) => load(projectPath).chromium.launch()
|
|
1
|
+
import { requirePeer } from './loadPeer.mjs'
|
|
2
|
+
|
|
3
|
+
const installHint = 'Install it in your project with: npm install --save-dev playwright'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Find Playwright (headless-browser automation) of the project being built, an optional peer dependency only
|
|
7
|
+
* needed by whatever actually drives a real browser - projects which never do never need it installed.
|
|
8
|
+
* @memberOf module:partials
|
|
9
|
+
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
10
|
+
* @returns {Object} The Playwright module.
|
|
11
|
+
* @throws {Error} With install instructions when playwright is not installed.
|
|
12
|
+
*/
|
|
13
|
+
export const loadPlaywright = (projectPath = process.cwd()) => requirePeer('playwright', { task: 'browser automation', installHint, projectPath })
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Launch a real headless Chromium browser via Playwright. See {@link loadPlaywright}.
|
|
17
|
+
* @memberOf module:partials
|
|
18
|
+
* @param {Function} [load=loadPlaywright] Which Playwright to launch - swappable in tests.
|
|
19
|
+
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
20
|
+
* @returns {Promise<Browser>} The running Playwright browser - close it yourself (browser.close()) once done with it.
|
|
21
|
+
* @throws {Error} With install instructions when playwright is not installed.
|
|
22
|
+
*/
|
|
23
|
+
export const launchBrowser = (load = loadPlaywright, projectPath = process.cwd()) => load(projectPath).chromium.launch()
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import * as setUp from '../test-helpers/setUp.mjs'
|
|
3
|
-
import { loadPlaywright, launchBrowser } from './loadPlaywright.mjs'
|
|
4
|
-
import { serveStatic } from './serveStatic.mjs'
|
|
5
|
-
|
|
6
|
-
setUp.setDefaults('test-load-playwright')
|
|
7
|
-
const gulpConfig = setUp.gulpConfig
|
|
8
|
-
|
|
9
|
-
beforeEach(setUp.beforeEach)
|
|
10
|
-
afterEach(setUp.afterEach)
|
|
11
|
-
|
|
12
|
-
describe('loadPlaywright', () => {
|
|
13
|
-
test('explains how to install playwright when the project does not have it', () => {
|
|
14
|
-
expect(() => loadPlaywright('/')).toThrow(/optional peer dependency playwright.*npm install --save-dev playwright/)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
// Unlike typedoc (ESM-only, see typeDocsFor.test.mjs), playwright is CommonJS-compatible, so its real loading can
|
|
18
|
-
// be tested directly here rather than only end to end.
|
|
19
|
-
test('loads the real playwright module from this project (its own devDependency)', () => {
|
|
20
|
-
const playwright = loadPlaywright()
|
|
21
|
-
expect(typeof playwright.chromium.launch).toBe('function')
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
describe('launchBrowser', () => {
|
|
26
|
-
test('resolves playwright (via the given loader) and launches its chromium', async () => {
|
|
27
|
-
const launch = jest.fn(() => Promise.resolve('a-real-browser'))
|
|
28
|
-
const load = jest.fn(() => ({ chromium: { launch } }))
|
|
29
|
-
await expect(launchBrowser(load, '/some/project')).resolves.toBe('a-real-browser')
|
|
30
|
-
expect(load).toHaveBeenCalledWith('/some/project')
|
|
31
|
-
expect(launch).toHaveBeenCalledTimes(1)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('defaults to the real loadPlaywright and launches a real, working browser', async () => {
|
|
35
|
-
const browser = await launchBrowser()
|
|
36
|
-
expect(browser.isConnected()).toBe(true)
|
|
37
|
-
await browser.close()
|
|
38
|
-
}, 30000)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe('a real page, served and loaded end to end', () => {
|
|
42
|
-
// The exact real-world case that motivated this partial: a page using a root-relative asset path
|
|
43
|
-
// (/style.css), which a bare file:// load resolves against the filesystem root instead of the page's own
|
|
44
|
-
// directory - serveStatic + a real browser is what actually proves this resolves correctly, not jsdom
|
|
45
|
-
// (which cannot execute <script type="module"> at all, the limitation this whole capability exists to close).
|
|
46
|
-
test('a page with a root-relative asset path loads correctly through a real server and a real browser', async () => {
|
|
47
|
-
const srcPath = gulpConfig.get('srcPath')
|
|
48
|
-
fs.mkdirSync(`${srcPath}/browser`, { recursive: true })
|
|
49
|
-
fs.writeFileSync(`${srcPath}/browser/style.css`, 'body { background-color: rgb(1, 2, 3); }')
|
|
50
|
-
fs.writeFileSync(`${srcPath}/index.html`, [
|
|
51
|
-
'<!doctype html><html><head>',
|
|
52
|
-
'<link rel="stylesheet" href="/browser/style.css">',
|
|
53
|
-
'<script type="module">document.title = \'loaded via a real module script\'</script>',
|
|
54
|
-
'</head><body></body></html>'
|
|
55
|
-
].join(''))
|
|
56
|
-
|
|
57
|
-
const { server, url } = await serveStatic(srcPath)
|
|
58
|
-
const browser = await launchBrowser()
|
|
59
|
-
try {
|
|
60
|
-
const page = await browser.newPage()
|
|
61
|
-
await page.goto(`${url}/index.html`)
|
|
62
|
-
expect(await page.title()).toBe('loaded via a real module script')
|
|
63
|
-
const backgroundColor = await page.evaluate(() => globalThis.getComputedStyle(document.body).backgroundColor)
|
|
64
|
-
expect(backgroundColor).toBe('rgb(1, 2, 3)')
|
|
65
|
-
} finally {
|
|
66
|
-
await browser.close()
|
|
67
|
-
server.close()
|
|
68
|
-
}
|
|
69
|
-
}, 30000)
|
|
70
|
-
})
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import * as setUp from '../test-helpers/setUp.mjs'
|
|
3
|
+
import { loadPlaywright, launchBrowser } from './loadPlaywright.mjs'
|
|
4
|
+
import { serveStatic } from './serveStatic.mjs'
|
|
5
|
+
|
|
6
|
+
setUp.setDefaults('test-load-playwright')
|
|
7
|
+
const gulpConfig = setUp.gulpConfig
|
|
8
|
+
|
|
9
|
+
beforeEach(setUp.beforeEach)
|
|
10
|
+
afterEach(setUp.afterEach)
|
|
11
|
+
|
|
12
|
+
describe('loadPlaywright', () => {
|
|
13
|
+
test('explains how to install playwright when the project does not have it', () => {
|
|
14
|
+
expect(() => loadPlaywright('/')).toThrow(/optional peer dependency playwright.*npm install --save-dev playwright/)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// Unlike typedoc (ESM-only, see typeDocsFor.test.mjs), playwright is CommonJS-compatible, so its real loading can
|
|
18
|
+
// be tested directly here rather than only end to end.
|
|
19
|
+
test('loads the real playwright module from this project (its own devDependency)', () => {
|
|
20
|
+
const playwright = loadPlaywright()
|
|
21
|
+
expect(typeof playwright.chromium.launch).toBe('function')
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('launchBrowser', () => {
|
|
26
|
+
test('resolves playwright (via the given loader) and launches its chromium', async () => {
|
|
27
|
+
const launch = jest.fn(() => Promise.resolve('a-real-browser'))
|
|
28
|
+
const load = jest.fn(() => ({ chromium: { launch } }))
|
|
29
|
+
await expect(launchBrowser(load, '/some/project')).resolves.toBe('a-real-browser')
|
|
30
|
+
expect(load).toHaveBeenCalledWith('/some/project')
|
|
31
|
+
expect(launch).toHaveBeenCalledTimes(1)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('defaults to the real loadPlaywright and launches a real, working browser', async () => {
|
|
35
|
+
const browser = await launchBrowser()
|
|
36
|
+
expect(browser.isConnected()).toBe(true)
|
|
37
|
+
await browser.close()
|
|
38
|
+
}, 30000)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('a real page, served and loaded end to end', () => {
|
|
42
|
+
// The exact real-world case that motivated this partial: a page using a root-relative asset path
|
|
43
|
+
// (/style.css), which a bare file:// load resolves against the filesystem root instead of the page's own
|
|
44
|
+
// directory - serveStatic + a real browser is what actually proves this resolves correctly, not jsdom
|
|
45
|
+
// (which cannot execute <script type="module"> at all, the limitation this whole capability exists to close).
|
|
46
|
+
test('a page with a root-relative asset path loads correctly through a real server and a real browser', async () => {
|
|
47
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
48
|
+
fs.mkdirSync(`${srcPath}/browser`, { recursive: true })
|
|
49
|
+
fs.writeFileSync(`${srcPath}/browser/style.css`, 'body { background-color: rgb(1, 2, 3); }')
|
|
50
|
+
fs.writeFileSync(`${srcPath}/index.html`, [
|
|
51
|
+
'<!doctype html><html><head>',
|
|
52
|
+
'<link rel="stylesheet" href="/browser/style.css">',
|
|
53
|
+
'<script type="module">document.title = \'loaded via a real module script\'</script>',
|
|
54
|
+
'</head><body></body></html>'
|
|
55
|
+
].join(''))
|
|
56
|
+
|
|
57
|
+
const { server, url } = await serveStatic(srcPath)
|
|
58
|
+
const browser = await launchBrowser()
|
|
59
|
+
try {
|
|
60
|
+
const page = await browser.newPage()
|
|
61
|
+
await page.goto(`${url}/index.html`)
|
|
62
|
+
expect(await page.title()).toBe('loaded via a real module script')
|
|
63
|
+
const backgroundColor = await page.evaluate(() => globalThis.getComputedStyle(document.body).backgroundColor)
|
|
64
|
+
expect(backgroundColor).toBe('rgb(1, 2, 3)')
|
|
65
|
+
} finally {
|
|
66
|
+
await browser.close()
|
|
67
|
+
server.close()
|
|
68
|
+
}
|
|
69
|
+
}, 30000)
|
|
70
|
+
})
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { dest, src } from 'gulp'
|
|
2
|
-
import { default as gulpUglify } from 'gulp-uglify-es'
|
|
3
|
-
import rename from 'gulp-rename'
|
|
4
|
-
|
|
5
|
-
const uglify = Object.hasOwn(gulpUglify, 'default') ? gulpUglify.default : gulpUglify
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Minify files and rename the output with '.min' extension.
|
|
9
|
-
* @memberOf module:partials
|
|
10
|
-
* @returns {*}
|
|
11
|
-
*/
|
|
12
|
-
export const minifyFor = (srcSearch, destination) => src(srcSearch)
|
|
13
|
-
.pipe(uglify())
|
|
14
|
-
.pipe(rename({ extname: '.min.js' }))
|
|
15
|
-
.pipe(dest(destination))
|
|
1
|
+
import { dest, src } from 'gulp'
|
|
2
|
+
import { default as gulpUglify } from 'gulp-uglify-es'
|
|
3
|
+
import rename from 'gulp-rename'
|
|
4
|
+
|
|
5
|
+
const uglify = Object.hasOwn(gulpUglify, 'default') ? gulpUglify.default : gulpUglify
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Minify files and rename the output with '.min' extension.
|
|
9
|
+
* @memberOf module:partials
|
|
10
|
+
* @returns {*}
|
|
11
|
+
*/
|
|
12
|
+
export const minifyFor = (srcSearch, destination) => src(srcSearch)
|
|
13
|
+
.pipe(uglify())
|
|
14
|
+
.pipe(rename({ extname: '.min.js' }))
|
|
15
|
+
.pipe(dest(destination))
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import * as setUp from '../test-helpers/setUp.mjs'
|
|
3
|
-
import { minifyFor } from './minifyFor.mjs'
|
|
4
|
-
import { countMatches } from 'test-filesystem'
|
|
5
|
-
|
|
6
|
-
setUp.setDefaults('test-minify-for')
|
|
7
|
-
const gulpConfig = setUp.gulpConfig
|
|
8
|
-
|
|
9
|
-
const rawContents = 'const { dest, src } = require(\'gulp\')\n' +
|
|
10
|
-
'const { default: uglify } = require(\'gulp-uglify-es\')\n' +
|
|
11
|
-
'const rename = require(\'gulp-rename\')\n' +
|
|
12
|
-
'\n' +
|
|
13
|
-
'/**\n' +
|
|
14
|
-
' * Minify files and rename the output with \'.min\' extension.\n' +
|
|
15
|
-
' * @returns {*}\n' +
|
|
16
|
-
' */\n' +
|
|
17
|
-
'const minifyFor = (srcSearch, destination) => src(srcSearch)\n' +
|
|
18
|
-
' .pipe(uglify())\n' +
|
|
19
|
-
' .pipe(rename({ extname: \'.min.js\' }))\n' +
|
|
20
|
-
' .pipe(dest(destination))\n' +
|
|
21
|
-
'\n' +
|
|
22
|
-
'module.exports = minifyFor\n'
|
|
23
|
-
|
|
24
|
-
beforeEach(() => setUp.beforeEach()
|
|
25
|
-
.then(() => fs.writeFileSync(gulpConfig.get('srcPath') + '/minifyFor.js', rawContents)))
|
|
26
|
-
|
|
27
|
-
afterEach(setUp.afterEach)
|
|
28
|
-
|
|
29
|
-
describe('minifyFor', () => {
|
|
30
|
-
test('copies the src directory and minifies it into the dist directory with min extension', done => {
|
|
31
|
-
const srcPath = gulpConfig.get('srcPath')
|
|
32
|
-
const filePath = `${srcPath}/minifyFor.js`
|
|
33
|
-
const expectedFilePath = `${srcPath}/minifyFor.min.js`
|
|
34
|
-
expect.assertions(3)
|
|
35
|
-
const oldContents = fs.readFileSync(filePath).toString()
|
|
36
|
-
expect(countMatches(oldContents, '\n')).toBe(14)
|
|
37
|
-
minifyFor(filePath, srcPath)
|
|
38
|
-
.on('finish', () => {
|
|
39
|
-
expect(fs.existsSync(expectedFilePath)).toBeTruthy()
|
|
40
|
-
const minifiedContents = fs.readFileSync(expectedFilePath).toString()
|
|
41
|
-
expect(countMatches(minifiedContents, '\n')).toBe(0)
|
|
42
|
-
done()
|
|
43
|
-
})
|
|
44
|
-
.on('error', error => {
|
|
45
|
-
console.error('Encountered error', error)
|
|
46
|
-
done()
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
})
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import * as setUp from '../test-helpers/setUp.mjs'
|
|
3
|
+
import { minifyFor } from './minifyFor.mjs'
|
|
4
|
+
import { countMatches } from 'test-filesystem'
|
|
5
|
+
|
|
6
|
+
setUp.setDefaults('test-minify-for')
|
|
7
|
+
const gulpConfig = setUp.gulpConfig
|
|
8
|
+
|
|
9
|
+
const rawContents = 'const { dest, src } = require(\'gulp\')\n' +
|
|
10
|
+
'const { default: uglify } = require(\'gulp-uglify-es\')\n' +
|
|
11
|
+
'const rename = require(\'gulp-rename\')\n' +
|
|
12
|
+
'\n' +
|
|
13
|
+
'/**\n' +
|
|
14
|
+
' * Minify files and rename the output with \'.min\' extension.\n' +
|
|
15
|
+
' * @returns {*}\n' +
|
|
16
|
+
' */\n' +
|
|
17
|
+
'const minifyFor = (srcSearch, destination) => src(srcSearch)\n' +
|
|
18
|
+
' .pipe(uglify())\n' +
|
|
19
|
+
' .pipe(rename({ extname: \'.min.js\' }))\n' +
|
|
20
|
+
' .pipe(dest(destination))\n' +
|
|
21
|
+
'\n' +
|
|
22
|
+
'module.exports = minifyFor\n'
|
|
23
|
+
|
|
24
|
+
beforeEach(() => setUp.beforeEach()
|
|
25
|
+
.then(() => fs.writeFileSync(gulpConfig.get('srcPath') + '/minifyFor.js', rawContents)))
|
|
26
|
+
|
|
27
|
+
afterEach(setUp.afterEach)
|
|
28
|
+
|
|
29
|
+
describe('minifyFor', () => {
|
|
30
|
+
test('copies the src directory and minifies it into the dist directory with min extension', done => {
|
|
31
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
32
|
+
const filePath = `${srcPath}/minifyFor.js`
|
|
33
|
+
const expectedFilePath = `${srcPath}/minifyFor.min.js`
|
|
34
|
+
expect.assertions(3)
|
|
35
|
+
const oldContents = fs.readFileSync(filePath).toString()
|
|
36
|
+
expect(countMatches(oldContents, '\n')).toBe(14)
|
|
37
|
+
minifyFor(filePath, srcPath)
|
|
38
|
+
.on('finish', () => {
|
|
39
|
+
expect(fs.existsSync(expectedFilePath)).toBeTruthy()
|
|
40
|
+
const minifiedContents = fs.readFileSync(expectedFilePath).toString()
|
|
41
|
+
expect(countMatches(minifiedContents, '\n')).toBe(0)
|
|
42
|
+
done()
|
|
43
|
+
})
|
|
44
|
+
.on('error', error => {
|
|
45
|
+
console.error('Encountered error', error)
|
|
46
|
+
done()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
})
|