-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(node): run tests against multiple package managers
This changes how `lavamoat` runs its tests. To prepare the tests, `test/prepare.js` is run. This invokes [corepack](https://npm.im/corepack) to switch between package managers and performs a clean install and setup using each. The package manager can be changed via environment variable. Motivation: After changing from Yarn to npm, we were concerned about breaking compat. This should ease our nerves a bit! Notes: - a new policy file was created in project `2` for `atob`; I'm not sure what caused this change. - Yarn _must_ have lockfiles or it will get confused about workspaces.
- Loading branch information
Showing
32 changed files
with
1,159 additions
and
1,817 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,3 +3,6 @@ ignores: | |
- 'ava' | ||
# tests - fake packages | ||
- 'two' | ||
|
||
# invoked as executable | ||
- 'corepack' |
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// @ts-check | ||
|
||
/** | ||
* Prepares test fixture directories for use by the test suite using an | ||
* arbitrary package manager set via the `LAVAMOAT_PM` env var. | ||
* | ||
* The default package manager is `npm@latest`. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
'use strict' | ||
|
||
const path = require('node:path') | ||
const { execFile } = require('node:child_process') | ||
const { promisify } = require('node:util') | ||
const { rm, readdir } = require('node:fs/promises') | ||
|
||
const exec = promisify(execFile) | ||
|
||
const LAVAMOAT_PM = process.env.LAVAMOAT_PM ?? 'npm@latest' | ||
const PROJECTS_DIR = path.join(__dirname, 'projects') | ||
|
||
/** | ||
* Blast `node_modules` in `cwd` | ||
* @param {string} cwd - Project dir | ||
* @returns {Promise<void>} | ||
*/ | ||
async function clean(cwd) { | ||
await rm(path.join(cwd, 'node_modules'), { recursive: true, force: true }) | ||
} | ||
|
||
/** | ||
* Install a project's deps via a package manager, run the `setup` script, then | ||
* execute `lavamoat` on the `index.js` file. | ||
* @param {string} cwd - Project dir | ||
* @returns {Promise<void>} | ||
*/ | ||
async function setup(cwd) { | ||
// it just so happens that both yarn and npm use the same commands here. | ||
// this is not guaranteed to always be the case! | ||
await exec('corepack', [LAVAMOAT_PM, 'install'], { cwd }) | ||
await exec('corepack', [LAVAMOAT_PM, 'run', 'setup'], { cwd }) | ||
await exec('node', [require.resolve('../src/cli'), '-a', 'index.js'], { | ||
cwd, | ||
}) | ||
} | ||
|
||
async function main() { | ||
if (process.version.startsWith('v14') && LAVAMOAT_PM.startsWith('yarn')) { | ||
console.error('Skipping Yarn setup for Node.js v14 due to incompatibilities') | ||
return | ||
} | ||
|
||
const dirents = await readdir(PROJECTS_DIR, { withFileTypes: true }) | ||
|
||
for (const dirent of dirents) { | ||
if (dirent.isDirectory()) { | ||
const cwd = path.join(PROJECTS_DIR, dirent.name) | ||
const relative = path.relative(process.cwd(), cwd) | ||
|
||
await clean(cwd) | ||
await setup(cwd) | ||
|
||
console.debug('Initialized "%s" using %s', relative, LAVAMOAT_PM) | ||
} | ||
} | ||
|
||
console.debug('Test fixtures prepared successfully') | ||
} | ||
|
||
if (require.main === module) { | ||
main().catch((err) => { | ||
console.error(err) | ||
process.exitCode = 1 | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock = false |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"a@file:./fake_node_modules/a": | ||
version "1.0.0" | ||
|
||
"b@file:./fake_node_modules/b": | ||
version "1.0.0" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock = false |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.