From 2ac25c7cbce2a3588c6ea8c131a9a4beb9262023 Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Fri, 1 Nov 2024 13:17:13 +0100 Subject: [PATCH] Add npm test --- test/dev.test.mjs | 11 +++++--- test/fixtures/two-fer/npm/.eslintrc | 14 ++++++++++ test/fixtures/two-fer/npm/.gitignore | 5 ++++ test/fixtures/two-fer/npm/.meta/config.json | 29 +++++++++++++++++++++ test/fixtures/two-fer/npm/.meta/proof.ci.js | 3 +++ test/fixtures/two-fer/npm/.meta/tests.toml | 12 +++++++++ test/fixtures/two-fer/npm/.npmrc | 1 + test/fixtures/two-fer/npm/LICENSE | 21 +++++++++++++++ test/fixtures/two-fer/npm/babel.config.js | 4 +++ test/fixtures/two-fer/npm/package.json | 29 +++++++++++++++++++++ test/fixtures/two-fer/npm/two-fer.js | 3 +++ test/fixtures/two-fer/npm/two-fer.spec.js | 15 +++++++++++ test/log.test.mjs | 4 +++ test/skip.test.mjs | 4 +++ test/smoke.test.mjs | 9 +++++++ test/taskid.test.mjs | 4 +++ 16 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/two-fer/npm/.eslintrc create mode 100644 test/fixtures/two-fer/npm/.gitignore create mode 100644 test/fixtures/two-fer/npm/.meta/config.json create mode 100644 test/fixtures/two-fer/npm/.meta/proof.ci.js create mode 100644 test/fixtures/two-fer/npm/.meta/tests.toml create mode 100644 test/fixtures/two-fer/npm/.npmrc create mode 100644 test/fixtures/two-fer/npm/LICENSE create mode 100644 test/fixtures/two-fer/npm/babel.config.js create mode 100644 test/fixtures/two-fer/npm/package.json create mode 100644 test/fixtures/two-fer/npm/two-fer.js create mode 100644 test/fixtures/two-fer/npm/two-fer.spec.js diff --git a/test/dev.test.mjs b/test/dev.test.mjs index 560baffa..6bfc6394 100644 --- a/test/dev.test.mjs +++ b/test/dev.test.mjs @@ -1,10 +1,15 @@ +/** + * $ corepack pnpm node test/dev.test.mjs + * + * or with all logs: + * + * $ corepack pnpm dlx cross-env SILENT=0 corepack pnpm node test/dev.test.mjs + */ + import { join } from 'node:path' import { assertPass } from './asserts.mjs' import { fixtures } from './paths.mjs' -// run this file like: -// corepack pnpm dlx cross-env SILENT=0 corepack pnpm node test/dev.test.mjs - assertPass( 'clock', join(fixtures, 'clock', 'pass'), diff --git a/test/fixtures/two-fer/npm/.eslintrc b/test/fixtures/two-fer/npm/.eslintrc new file mode 100644 index 00000000..1d444602 --- /dev/null +++ b/test/fixtures/two-fer/npm/.eslintrc @@ -0,0 +1,14 @@ +{ + "root": true, + "extends": "@exercism/eslint-config-javascript", + "env": { + "jest": true + }, + "overrides": [ + { + "files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"], + "excludedFiles": ["custom.spec.js"], + "extends": "@exercism/eslint-config-javascript/maintainers" + } + ] +} diff --git a/test/fixtures/two-fer/npm/.gitignore b/test/fixtures/two-fer/npm/.gitignore new file mode 100644 index 00000000..31c57dd5 --- /dev/null +++ b/test/fixtures/two-fer/npm/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/bin/configlet +/bin/configlet.exe +/pnpm-lock.yaml +/yarn.lock diff --git a/test/fixtures/two-fer/npm/.meta/config.json b/test/fixtures/two-fer/npm/.meta/config.json new file mode 100644 index 00000000..d9490b6b --- /dev/null +++ b/test/fixtures/two-fer/npm/.meta/config.json @@ -0,0 +1,29 @@ +{ + "authors": [ + "laurmurclar" + ], + "contributors": [ + "mluisamc", + "serixscorpio", + "SleeplessByte" + ], + "files": { + "solution": [ + "two-fer.js" + ], + "test": [ + "two-fer.spec.js" + ], + "example": [ + ".meta/proof.ci.js" + ] + }, + "blurb": "Create a sentence of the form \"One for X, one for me.\".", + "source_url": "https://github.com/exercism/problem-specifications/issues/757", + "custom": { + "version.tests.compatibility": "jest-27", + "flag.tests.task-per-describe": false, + "flag.tests.may-run-long": false, + "flag.tests.includes-optional": false + } +} diff --git a/test/fixtures/two-fer/npm/.meta/proof.ci.js b/test/fixtures/two-fer/npm/.meta/proof.ci.js new file mode 100644 index 00000000..ac908cf3 --- /dev/null +++ b/test/fixtures/two-fer/npm/.meta/proof.ci.js @@ -0,0 +1,3 @@ +export const twoFer = (name = 'you') => { + return `One for ${name}, one for me.`; +}; diff --git a/test/fixtures/two-fer/npm/.meta/tests.toml b/test/fixtures/two-fer/npm/.meta/tests.toml new file mode 100644 index 00000000..3dae13cf --- /dev/null +++ b/test/fixtures/two-fer/npm/.meta/tests.toml @@ -0,0 +1,12 @@ +# This is an auto-generated file. Regular comments will be removed when this +# file is regenerated. Regenerating will not touch any manually added keys, +# so comments can be added in a "comment" key. + +[1cf3e15a-a3d7-4a87-aeb3-ba1b43bc8dce] +description = "no name given" + +[b4c6dbb8-b4fb-42c2-bafd-10785abe7709] +description = "a name given" + +[3549048d-1a6e-4653-9a79-b0bda163e8d5] +description = "another name given" diff --git a/test/fixtures/two-fer/npm/.npmrc b/test/fixtures/two-fer/npm/.npmrc new file mode 100644 index 00000000..d26df800 --- /dev/null +++ b/test/fixtures/two-fer/npm/.npmrc @@ -0,0 +1 @@ +audit=false diff --git a/test/fixtures/two-fer/npm/LICENSE b/test/fixtures/two-fer/npm/LICENSE new file mode 100644 index 00000000..90e73be0 --- /dev/null +++ b/test/fixtures/two-fer/npm/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Exercism + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/two-fer/npm/babel.config.js b/test/fixtures/two-fer/npm/babel.config.js new file mode 100644 index 00000000..b781d5a6 --- /dev/null +++ b/test/fixtures/two-fer/npm/babel.config.js @@ -0,0 +1,4 @@ +module.exports = { + presets: ['@exercism/babel-preset-javascript'], + plugins: [], +}; diff --git a/test/fixtures/two-fer/npm/package.json b/test/fixtures/two-fer/npm/package.json new file mode 100644 index 00000000..105457b8 --- /dev/null +++ b/test/fixtures/two-fer/npm/package.json @@ -0,0 +1,29 @@ +{ + "name": "@exercism/javascript-two-fer", + "description": "Exercism exercises in Javascript.", + "author": "Katrina Owen", + "private": true, + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/exercism/javascript", + "directory": "exercises/practice/two-fer" + }, + "devDependencies": { + "@babel/core": "^7.25.2", + "@exercism/babel-preset-javascript": "^0.2.1", + "@exercism/eslint-config-javascript": "^0.6.0", + "@types/jest": "^29.5.12", + "@types/node": "^20.12.12", + "babel-jest": "^29.6.4", + "core-js": "~3.37.1", + "eslint": "^8.49.0", + "jest": "^29.7.0" + }, + "dependencies": {}, + "scripts": { + "test": "jest ./*", + "watch": "jest --watch ./*", + "lint": "eslint ." + } +} diff --git a/test/fixtures/two-fer/npm/two-fer.js b/test/fixtures/two-fer/npm/two-fer.js new file mode 100644 index 00000000..ac908cf3 --- /dev/null +++ b/test/fixtures/two-fer/npm/two-fer.js @@ -0,0 +1,3 @@ +export const twoFer = (name = 'you') => { + return `One for ${name}, one for me.`; +}; diff --git a/test/fixtures/two-fer/npm/two-fer.spec.js b/test/fixtures/two-fer/npm/two-fer.spec.js new file mode 100644 index 00000000..1c39a365 --- /dev/null +++ b/test/fixtures/two-fer/npm/two-fer.spec.js @@ -0,0 +1,15 @@ +import { twoFer } from './two-fer'; + +describe('twoFer()', () => { + test('no name given', () => { + expect(twoFer()).toEqual('One for you, one for me.'); + }); + + xtest('a name given', () => { + expect(twoFer('Alice')).toEqual('One for Alice, one for me.'); + }); + + xtest('another name given', () => { + expect(twoFer('Bob')).toEqual('One for Bob, one for me.'); + }); +}); diff --git a/test/log.test.mjs b/test/log.test.mjs index ef896915..8bbe2431 100644 --- a/test/log.test.mjs +++ b/test/log.test.mjs @@ -1,3 +1,7 @@ +/** + * $ corepack pnpm node test/log.test.mjs + */ + import shelljs from 'shelljs' import { existsSync, mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' diff --git a/test/skip.test.mjs b/test/skip.test.mjs index cacb0e28..9d182c8b 100644 --- a/test/skip.test.mjs +++ b/test/skip.test.mjs @@ -1,3 +1,7 @@ +/** + * $ corepack pnpm node test/skip.test.mjs + */ + import { join } from 'node:path' import shelljs from 'shelljs' import { assertPass } from './asserts.mjs' diff --git a/test/smoke.test.mjs b/test/smoke.test.mjs index c22e7078..f06cb2b6 100644 --- a/test/smoke.test.mjs +++ b/test/smoke.test.mjs @@ -1,3 +1,7 @@ +/** + * $ corepack pnpm node test/smoke.test.mjs + */ + import { join } from 'node:path' import shelljs from 'shelljs' import { assertError, assertPass, rejectPass } from './asserts.mjs' @@ -25,6 +29,11 @@ assertPass( join(fixtures, 'poetry-club-door-policy', 'pass') ) +shelljs.echo( + 'javascript-test-runner > passing solution > uses npm instead of pnpm' +) +assertPass('two-fer', join(fixtures, 'two-fer', 'npm')) + /** Test failures */ const failures = ['tests', 'empty'] diff --git a/test/taskid.test.mjs b/test/taskid.test.mjs index 6b22b3ec..f3b670cf 100644 --- a/test/taskid.test.mjs +++ b/test/taskid.test.mjs @@ -1,3 +1,7 @@ +/** + * $ corepack pnpm node test/taskid.test.mjs + */ + import { mkdtempSync, readFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path'