Skip to content

Commit

Permalink
fix: update dependencies, require Node 18+ (#23)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: require Node 18+
  • Loading branch information
nolanlawson authored Jan 18, 2024
1 parent 8ac9949 commit c62a201
Show file tree
Hide file tree
Showing 5 changed files with 2,155 additions and 2,933 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ '14', '16', '18' ]
node-version: [ '18.0.0', '20' ]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@
"lwc-codemod": "transforms/cli.js"
},
"dependencies": {
"@lwc/template-compiler": "^3.0.1",
"jscodeshift": "^0.13.1",
"parse5": "^6.0.1",
"postcss": "^8.4.5",
"postcss-selector-parser": "^6.0.9"
"@lwc/template-compiler": "^6.0.0",
"jscodeshift": "^0.15.1",
"parse5": "^7.1.2",
"postcss": "^8.4.33",
"postcss-selector-parser": "^6.0.15"
},
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest ./tests/*.spec.js",
"test:debug": "NODE_OPTIONS='--experimental-vm-modules --inspect-brk' jest --runInBand ./tests/*.spec.js",
"lint": "standard"
},
"devDependencies": {
"glob": "^7.2.0",
"jest": "^27.4.7",
"standard": "^16.0.4"
"jest": "^29.7.0",
"standard": "^17.1.0"
},
"volta": {
"node": "16.10.0",
"yarn": "1.22.15"
"node": "20.11.0",
"yarn": "1.22.21"
},
"standard": {
"globals": [
Expand All @@ -47,7 +46,7 @@
"transforms"
],
"engines": {
"node": ">=14.13.1"
"node": ">=18.0.0"
},
"repository": {
"type": "git",
Expand Down
14 changes: 5 additions & 9 deletions tests/fixtures.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { jest } from '@jest/globals'
import { testFixtureDir } from './utils/jestUtils.js'
import { main } from '../transforms/index.js'
import { copyDir, getAllFilesInDir } from '../transforms/fsUtils.js'
import path from 'path'
import { readdirSync } from 'fs'
import fs from 'fs/promises'
import os from 'os'
import path from 'node:path'
import { readdirSync } from 'node:fs'
import fs from 'node:fs/promises'
import os from 'node:os'
import { observer } from '../transforms/observer.js'

jest.setTimeout(60000)
Expand All @@ -20,11 +20,7 @@ describe('fixtures', () => {
const transforms = readdirSync('./tests/fixtures')
for (const transform of transforms) {
describe(transform, () => {
testFixtureDir(
{
root: `./tests/fixtures/${transform}`,
pattern: '**/input'
},
testFixtureDir(`./tests/fixtures/${transform}`,
async ({ dirname }) => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'lwc-codemod-'))
const expectedDir = path.join(path.dirname(dirname), 'expected')
Expand Down
50 changes: 31 additions & 19 deletions tests/utils/jestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
// via https://github.com/salesforce/lwc/blob/81a90709bb6eb84b41f1cfe29d6afe15c9a97a13/scripts/jest/utils/index.ts
import fs from 'fs'
import path from 'path'
import glob from 'glob'
import fs from 'node:fs'
import path from 'node:path'

// Based on https://github.com/fs-utils/fs-readdir-recursive/blob/f810b44/index.js
// Can be replaced with fs.readdirSync(..., { recursive: true }) when we drop Node 18 support
function readdirRecursiveSync (root, files, prefix) {
prefix = prefix || ''
files = files || []

const dir = path.join(root, prefix)
if (fs.existsSync(dir)) {
if (prefix) {
files.push(prefix)
}
if (fs.statSync(dir).isDirectory()) {
for (const name of fs.readdirSync(dir)) {
readdirRecursiveSync(root, files, path.join(prefix, name))
}
}
}

return files
}

function toMatchFile (receivedContent, filename) {
const { snapshotState, expand, utils } = this
Expand Down Expand Up @@ -93,22 +113,14 @@ function toMatchFile (receivedContent, filename) {
// Register jest matcher.
expect.extend({ toMatchFile })

export function testFixtureDir (config, testFn) {
if (typeof config !== 'object' || config === null) {
throw new TypeError('Expected first argument to be an object')
}
if (typeof testFn !== 'function') {
throw new TypeError('Expected second argument to be a function')
}
const { pattern, root } = config
if (!pattern || !root) {
throw new TypeError('Expected a "root" and a "pattern" config to be specified')
}
const matches = glob.sync(pattern, {
cwd: root,
absolute: true
})
for (const dirname of matches) {
export function testFixtureDir (root, testFn) {
// find all directories matching `input`. these may be deeply nested

const inputDirs = readdirRecursiveSync(root)
.filter(_ => _.endsWith('/input'))
.map(_ => path.resolve(root, _))

for (const dirname of inputDirs) {
const fixtureName = path.relative(root, dirname)
test(fixtureName.replace('/input', ''), async () => {
const outputs = await testFn({
Expand Down
Loading

0 comments on commit c62a201

Please sign in to comment.