Skip to content

Commit

Permalink
Get tests running in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Oct 2, 2024
1 parent b57863c commit 136965f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 28 deletions.
4 changes: 3 additions & 1 deletion scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const NODE_VERSION = process.versions.node
const NPM_ORG = 'socketregistry'
const OVERRIDES = 'overrides'
const PACKAGE_DEFAULT_SOCKET_CATEGORIES = Object.freeze(['cleanup'])
const PACKAGE_DEFAULT_VERSION = '1.0.0'
const PACKAGE_JSON = 'package.json'
const PACKAGE_LOCK = 'package-lock.json'
const PACKAGE_SCOPE = `@${NPM_ORG}`
Expand All @@ -102,7 +103,7 @@ const TEMPLATE_ES_SHIM_STATIC_METHOD = 'es-shim-static-method'
const TSCONFIG_JSON = 'tsconfig.json'
const UNLICENCED = 'UNLICENCED'
const UNLICENSED = 'UNLICENSED'
const PACKAGE_DEFAULT_VERSION = '1.0.0'
const WIN_32 = process.platform === 'win32'

const rootPath = path.resolve(__dirname, '..')
const rootLicensePath = path.join(rootPath, LICENSE)
Expand Down Expand Up @@ -488,6 +489,7 @@ const constants = Object.freeze(
TSCONFIG_JSON,
UNLICENCED,
UNLICENSED,
WIN_32,
ciTapConfigPath,
copyLeftLicenses,
ecosystems: undefined,
Expand Down
11 changes: 5 additions & 6 deletions scripts/make-npm-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const path = require('node:path')
const util = require('node:util')

const spawn = require('@npmcli/promise-spawn')
const { ReturnTypeEnums, default: didYouMean } = require('didyoumean2')
const fs = require('fs-extra')
const { open } = require('out-url')
Expand All @@ -21,14 +20,14 @@ const {
TEMPLATE_ES_SHIM_CONSTRUCTOR,
TEMPLATE_ES_SHIM_PROTOTYPE_METHOD,
TEMPLATE_ES_SHIM_STATIC_METHOD,
execPath,
npmPackagesPath,
rootPath,
tsLibs,
tsTypes
} = constants
const { isDirEmptySync } = require('@socketregistry/scripts/utils/fs')
const { globLicenses } = require('@socketregistry/scripts/utils/globs')
const { runBin } = require('@socketregistry/scripts/utils/npm')
const { isObject } = require('@socketregistry/scripts/utils/objects')
const {
collectIncompatibleLicenses,
Expand Down Expand Up @@ -416,17 +415,17 @@ function toChoice(value) {

// Update monorepo package.json workspaces definition and test/npm files.
try {
await spawn(
execPath,
await runBin(
// Lazily access constants.runScriptParallelExecPath.
constants.runScriptParallelExecPath,
[
// Lazily access constants.runScriptParallelExecPath.
constants.runScriptParallelExecPath,
'update:manifest',
'update:package-json',
`update:longtask:test:npm:package-json -- --add ${pkgName}`
],
{
cwd: rootPath,
shell: true,
stdio: 'inherit'
}
)
Expand Down
29 changes: 16 additions & 13 deletions scripts/tap.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
'use strict'

const spawn = require('@npmcli/promise-spawn')

const constants = require('@socketregistry/scripts/constants')
const { ENV, ciTapConfigPath, execPath, rootPath, rootTapConfigPath } =
constants
const { ENV, ciTapConfigPath, rootPath, rootTapConfigPath } = constants
const { runBin } = require('@socketregistry/scripts/utils/npm')

;(async () => {
// Lazily access constants.tapRunExecPath.
await spawn(execPath, [constants.tapRunExecPath, ...process.argv.slice(2)], {
cwd: rootPath,
stdio: 'inherit',
env: {
__proto__: null,
...process.env,
TAP_RCFILE: ENV.CI ? ciTapConfigPath : rootTapConfigPath
await runBin(
// Lazily access constants.tapRunExecPath.
constants.tapRunExecPath,
process.argv.slice(2),
{
cwd: rootPath,
shell: true,
stdio: 'inherit',
env: {
__proto__: null,
...process.env,
TAP_RCFILE: ENV.CI ? ciTapConfigPath : rootTapConfigPath
}
}
})
)
})()
1 change: 1 addition & 0 deletions scripts/update-package-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function modifyYarnpkgExtsPkgJson() {
// Lazily access constants.npmExecPath.
await spawn(constants.npmExecPath, ['install'], {
cwd: rootPath,
shell: true,
stdio: 'inherit'
})
}
Expand Down
5 changes: 4 additions & 1 deletion scripts/update-test-npm-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ async function installTestNpmNodeModules(options) {
args.push('--save-dev', ...specs)
}
// Lazily access constants.npmExecPath.
return await spawn(constants.npmExecPath, args, { cwd: testNpmPath })
return await spawn(constants.npmExecPath, args, {
cwd: testNpmPath,
shell: true
})
}

const editablePackageJsonCache = { __proto__: null }
Expand Down
1 change: 1 addition & 0 deletions scripts/utils/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const gitDiffSpawnArgs = defineLazyGetters(
['diff', '--cached', '--name-only'],
{
cwd: rootPath,
shell: true,
encoding: 'utf8'
}
]
Expand Down
18 changes: 18 additions & 0 deletions scripts/utils/npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const spawn = require('@npmcli/promise-spawn')

const constants = require('@socketregistry/scripts/constants')
const { WIN_32, execPath } = constants

async function runBin(binPath, args, options) {
return await spawn(
WIN_32 ? binPath : execPath,
[...(WIN_32 ? [] : [binPath]), ...args],
options
)
}

module.exports = {
runBin
}
15 changes: 8 additions & 7 deletions test/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'node:path'
import { describe, it } from 'node:test'
import util from 'node:util'

import spawn from '@npmcli/promise-spawn'
import fs from 'fs-extra'
import semver from 'semver'

Expand All @@ -15,7 +14,6 @@ const {
NODE_VERSION,
PACKAGE_JSON,
README_GLOB_RECURSIVE,
execPath,
parseArgsConfig,
testNpmNodeWorkspacesPath
} = constants
Expand All @@ -27,6 +25,8 @@ import {
// @ts-ignore
} from '@socketregistry/scripts/utils/git'
// @ts-ignore
import { runBin } from '@socketregistry/scripts/utils/npm'
// @ts-ignore
import { isNonEmptyString } from '@socketregistry/scripts/utils/strings'

// Use by passing as a tap --test-arg:
Expand Down Expand Up @@ -78,12 +78,13 @@ describe('npm', async () => {

it(`${pkgName} passes all its tests`, { skip }, async () => {
try {
// Lazily access constants.runScriptSequentiallyExecPath.
await spawn(
execPath,
[constants.runScriptSequentiallyExecPath, 'test'],
await runBin(
// Lazily access constants.runScriptSequentiallyExecPath.
constants.runScriptSequentiallyExecPath,
['test'],
{
cwd: nwPkgPath
cwd: nwPkgPath,
shell: true
}
)
assert.ok(true)
Expand Down

0 comments on commit 136965f

Please sign in to comment.