Skip to content

Commit

Permalink
Reduce tests run on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Oct 5, 2024
1 parent 2130834 commit d5e7073
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
17 changes: 17 additions & 0 deletions scripts/utils/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const { PackageURL } = require('packageurl-js')

const registryManifest = require('@socketsecurity/registry')

function getManifestData(eco, regPkgName) {
return registryManifest[eco]
.find(
({ 0: purlStr }) => PackageURL.fromString(purlStr).name === regPkgName
)
?.at(1)
}

module.exports = {
getManifestData
}
15 changes: 3 additions & 12 deletions scripts/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const {
TEMPLATE_ES_SHIM_STATIC_METHOD,
npmTemplatesPath
} = constants
const { getManifestData } = require('@socketregistry/scripts/utils//manifest')
const { globLicenses } = require('@socketregistry/scripts/utils/globs')
const { isObjectObject } = require('@socketregistry/scripts/utils/objects')
const {
readPackageJson,
resolveOriginalPackageName
} = require('@socketregistry/scripts/utils/packages')
const { prettierFormat } = require('@socketregistry/scripts/utils/strings')
const registryManifest = require('@socketsecurity/registry')

const eta = new Eta()

Expand Down Expand Up @@ -73,22 +73,14 @@ async function getLicenseActions(pkgPath) {
return actions
}

function getManifestData(regPkgName) {
return registryManifest.npm
.find(
({ 0: purlStr }) => PackageURL.fromString(purlStr).name === regPkgName
)
?.at(1)
}

async function getNpmReadmeAction(pkgPath) {
const pkgJsonPath = path.join(pkgPath, PACKAGE_JSON)
const pkgJson = await readPackageJson(pkgJsonPath)
const pkgPurlObj = PackageURL.fromString(
`pkg:npm/${pkgJson.name}@${pkgJson.version}`
)
const { name: regPkgName } = pkgPurlObj
const manifestData = getManifestData(regPkgName)
const manifestData = getManifestData('npm', regPkgName)
const categories = manifestData?.categories
return [
path.join(pkgPath, README_MD),
Expand Down Expand Up @@ -116,7 +108,7 @@ async function getNpmReadmeAction(pkgPath) {
async function getPackageJsonAction(pkgPath, options) {
const { engines } = { __proto__: null, ...options }
const regPkgName = path.basename(pkgPath)
const manifestData = getManifestData(regPkgName)
const manifestData = getManifestData('npm', regPkgName)
const categories = manifestData?.categories
return [
path.join(pkgPath, PACKAGE_JSON),
Expand Down Expand Up @@ -175,7 +167,6 @@ async function writeAction(action) {

module.exports = {
getLicenseActions,
getManifestData,
getNpmReadmeAction,
getPackageJsonAction,
getTypeScriptActions,
Expand Down
5 changes: 5 additions & 0 deletions test/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
NODE_VERSION,
PACKAGE_JSON,
README_GLOB_RECURSIVE,
WIN_32,
parseArgsConfig,
skipTestsByEcosystem,
testNpmNodeWorkspacesPath
Expand All @@ -26,6 +27,8 @@ import {
// @ts-ignore
} from '@socketregistry/scripts/utils/git'
// @ts-ignore
import { getManifestData } from '@socketregistry/scripts/utils/manifest'
// @ts-ignore
import { runScript } from '@socketregistry/scripts/utils/npm'
import {
resolveOriginalPackageName
Expand Down Expand Up @@ -61,8 +64,10 @@ describe('npm', async () => {
const nwPkgJson = fs.readJsonSync(path.join(nwPkgPath, PACKAGE_JSON))
const nodeRange = nwPkgJson.engines?.node
const origPkgName = resolveOriginalPackageName(regPkgName)
const manifestData = getManifestData('npm', regPkgName)
const skip =
!nwPkgJson.scripts?.test ||
(WIN_32 && !manifestData.interop.includes('browserify')) ||
(isNonEmptyString(nodeRange) &&
!semver.satisfies(NODE_VERSION, nodeRange))

Expand Down
6 changes: 3 additions & 3 deletions test/packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
// @ts-ignore
} from '@socketregistry/scripts/utils/git'
// @ts-ignore
import { getManifestData } from '@socketregistry/scripts/utils/manifest'
// @ts-ignore
import { isObjectObject } from '@socketregistry/scripts/utils/objects'
import {
findTypesForSubpath,
Expand All @@ -44,8 +46,6 @@ import { trimLeadingDotSlash } from '@socketregistry/scripts/utils/path'
import { localeCompare } from '@socketregistry/scripts/utils/sorts'
// @ts-ignore
import { isNonEmptyString } from '@socketregistry/scripts/utils/strings'
// @ts-ignore
import { getManifestData } from '@socketregistry/scripts/utils/templates'

// Use by passing as a tap --test-arg:
// npm run test:unit ./test/packages.test.ts -- --test-arg="--force"
Expand Down Expand Up @@ -233,7 +233,7 @@ for (const eco of constants.ecosystems) {
)
})

const manifestData = getManifestData(regPkgName)
const manifestData = getManifestData(eco, regPkgName)
if (manifestData?.license !== 'Public Domain') {
it(`should have an original license file`, () => {
assert.ok(files.some(p => p.includes('.original')))
Expand Down

0 comments on commit d5e7073

Please sign in to comment.