-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
6,115 additions
and
8,164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,14 @@ jobs: | |
needs: test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
with: | ||
lfs: true | ||
ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && | ||
github.event.pull_request.head.ref || '' }} | ||
- uses: actions/setup-node@v3 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 16 | ||
node-version: 20 | ||
- run: git config --global user.email "[email protected]" | ||
- run: git config --global user.name "GitHub Actions" | ||
- run: yarn --frozen-lockfile | ||
|
@@ -38,11 +38,11 @@ jobs: | |
needs: cancel-existing | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
lfs: true | ||
- uses: actions/setup-node@v3 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- run: yarn --frozen-lockfile | ||
|
@@ -54,20 +54,20 @@ jobs: | |
with: | ||
name: Image Snapshot Diffs | ||
path: "**/__image_snapshots__/__diff_output__" | ||
- if: matrix.os == 'ubuntu-latest' && matrix.node == 16 | ||
- if: matrix.os == 'ubuntu-latest' && matrix.node == 20 | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
strategy: | ||
matrix: | ||
include: | ||
- node: 14 | ||
- node: 18 | ||
os: ubuntu-latest | ||
- node: 16 | ||
- node: 20 | ||
os: ubuntu-latest | ||
- node: 16 | ||
- node: 20 | ||
os: macos-latest | ||
- node: 16 | ||
- node: 20 | ||
os: windows-latest | ||
name: build | ||
on: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ jobs: | |
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: jaid/[email protected] | ||
with: | ||
approve: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ vscode: | |
- https://sebastianlandwehr.com/vscode-extensions/karlito40.fix-irregular-whitespace-0.1.1.vsix | ||
- https://sebastianlandwehr.com/vscode-extensions/adrianwilczynski.toggle-hidden-1.0.2.vsix | ||
- [email protected] | ||
- Tobermory.es6-string-html | ||
- zjcompt.es6-string-javascript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import { addPluginTemplate, isNuxt3 as isNuxt3Try } from '@nuxt/kit' | ||
import modernizr from 'modernizr' | ||
import { createRequire } from 'module' | ||
import nuxtPushPlugins from 'nuxt-push-plugins' | ||
import P from 'path' | ||
|
||
const _require = createRequire(import.meta.url) | ||
const resolver = createRequire(import.meta.url) | ||
|
||
export default async function (moduleOptions) { | ||
const options = { ...this.options.modernizr, ...moduleOptions } | ||
export default async function (moduleOptions, nuxt) { | ||
let isNuxt3 = true | ||
try { | ||
isNuxt3 = isNuxt3Try() | ||
} catch { | ||
isNuxt3 = false | ||
} | ||
nuxt = nuxt || this | ||
|
||
const options = { ...nuxt.options.modernizr, ...moduleOptions } | ||
|
||
const code = await new Promise(resolve => modernizr.build(options, resolve)) | ||
nuxtPushPlugins(this, { | ||
fileName: P.join('nuxt-modernizr', 'plugin.js'), | ||
mode: 'client', | ||
options: code, | ||
src: _require.resolve('./plugin.js.template'), | ||
}) | ||
if (isNuxt3) { | ||
addPluginTemplate({ | ||
filename: P.join('nuxt-modernizr', 'plugin.js'), | ||
getContents: () => `export default defineNuxtPlugin(() => { ${code} })`, | ||
mode: 'client', | ||
}) | ||
} else { | ||
nuxtPushPlugins(nuxt, { | ||
fileName: P.join('nuxt-modernizr', 'plugin.js'), | ||
mode: 'client', | ||
options: code, | ||
src: resolver.resolve('./plugin.js.template'), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,106 @@ | ||
import { endent, mapValues, noop } from '@dword-design/functions' | ||
import puppeteer from '@dword-design/puppeteer' | ||
import { outputFile } from 'fs-extra' | ||
import { Builder, Nuxt } from 'nuxt' | ||
import withLocalTmpDir from 'with-local-tmp-dir' | ||
import { endent } from '@dword-design/functions' | ||
import tester from '@dword-design/tester' | ||
import testerPluginPuppeteer from '@dword-design/tester-plugin-puppeteer' | ||
import testerPluginTmpDir from '@dword-design/tester-plugin-tmp-dir' | ||
import { execaCommand } from 'execa' | ||
import fs from 'fs-extra' | ||
import nuxtDevReady from 'nuxt-dev-ready' | ||
import ora from 'ora' | ||
import outputFiles from 'output-files' | ||
import P from 'path' | ||
import kill from 'tree-kill-promise' | ||
|
||
import self from './index.js' | ||
|
||
let browser | ||
let page | ||
|
||
const runTest = config => () => { | ||
config = { test: noop, ...config } | ||
|
||
return withLocalTmpDir(async () => { | ||
await outputFile('pages/index.vue', config.page) | ||
|
||
const nuxt = new Nuxt({ | ||
dev: false, | ||
modules: [ | ||
[ | ||
self, | ||
{ | ||
'feature-detects': ['css/rgba'], | ||
options: ['setClasses'], | ||
}, | ||
], | ||
], | ||
}) | ||
await new Builder(nuxt).build() | ||
await nuxt.listen() | ||
try { | ||
await page.goto('http://localhost:3000') | ||
await config.test() | ||
} finally { | ||
await nuxt.close() | ||
} | ||
}) | ||
} | ||
export default tester( | ||
{ | ||
async nuxt2() { | ||
await outputFiles({ | ||
'nuxt.config.js': endent` | ||
export default { | ||
modules: [ | ||
[ | ||
'~/../src/index.js', | ||
{ | ||
'feature-detects': ['css/rgba'], | ||
options: ['setClasses'], | ||
}, | ||
], | ||
], | ||
} | ||
`, | ||
'pages/index.vue': endent` | ||
<template> | ||
<div /> | ||
</template> | ||
`, | ||
}) | ||
await fs.remove('node_modules') | ||
await fs.symlink( | ||
P.join('..', 'node_modules', '.cache', 'nuxt2', 'node_modules'), | ||
'node_modules', | ||
) | ||
|
||
export default { | ||
after: () => browser.close(), | ||
before: async () => { | ||
browser = await puppeteer.launch() | ||
page = await browser.newPage() | ||
}, | ||
...({ | ||
valid: { | ||
page: endent` | ||
<script> | ||
export default { | ||
render() { | ||
return <div /> | ||
const nuxt = execaCommand('node_modules/.bin/nuxt dev') | ||
try { | ||
await nuxtDevReady() | ||
await this.page.goto('http://localhost:3000') | ||
await this.page.waitForSelector('html.rgba') | ||
expect( | ||
await this.page.evaluate(() => window.Modernizr.rgba), | ||
).toBeTruthy() | ||
} finally { | ||
await kill(nuxt.pid) | ||
} | ||
}, | ||
async valid() { | ||
await outputFiles({ | ||
'nuxt.config.js': endent` | ||
export default { | ||
modules: [ | ||
[ | ||
'../src/index.js', | ||
{ | ||
'feature-detects': ['css/rgba'], | ||
options: ['setClasses'], | ||
}, | ||
], | ||
], | ||
} | ||
} | ||
</script> | ||
`, | ||
'pages/index.vue': endent` | ||
<template> | ||
<div /> | ||
</template> | ||
`, | ||
}) | ||
|
||
`, | ||
test: async () => { | ||
await page.waitForSelector('html.rgba') | ||
expect(await page.evaluate(() => window.Modernizr.rgba)).toBeTruthy() | ||
const nuxt = execaCommand('nuxt dev') | ||
try { | ||
await nuxtDevReady() | ||
await this.page.goto('http://localhost:3000') | ||
await this.page.waitForSelector('html.rgba') | ||
expect( | ||
await this.page.evaluate(() => window.Modernizr.rgba), | ||
).toBeTruthy() | ||
} finally { | ||
await kill(nuxt.pid) | ||
} | ||
}, | ||
}, | ||
[ | ||
testerPluginTmpDir(), | ||
testerPluginPuppeteer(), | ||
{ | ||
before: async () => { | ||
const spinner = ora('Installing Nuxt 2').start() | ||
await fs.outputFile( | ||
P.join('node_modules', '.cache', 'nuxt2', 'package.json'), | ||
JSON.stringify({}), | ||
) | ||
await execaCommand('yarn add nuxt@^2 @nuxt/content@^1', { | ||
cwd: P.join('node_modules', '.cache', 'nuxt2'), | ||
}) | ||
spinner.stop() | ||
}, | ||
}, | ||
} |> mapValues(runTest)), | ||
} | ||
], | ||
) |
Oops, something went wrong.