Skip to content

Commit

Permalink
Add npm test
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte committed Nov 1, 2024
1 parent f200f00 commit 2ac25c7
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 3 deletions.
11 changes: 8 additions & 3 deletions test/dev.test.mjs
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/two-fer/npm/.eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
5 changes: 5 additions & 0 deletions test/fixtures/two-fer/npm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/bin/configlet
/bin/configlet.exe
/pnpm-lock.yaml
/yarn.lock
29 changes: 29 additions & 0 deletions test/fixtures/two-fer/npm/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions test/fixtures/two-fer/npm/.meta/proof.ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const twoFer = (name = 'you') => {
return `One for ${name}, one for me.`;
};
12 changes: 12 additions & 0 deletions test/fixtures/two-fer/npm/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions test/fixtures/two-fer/npm/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
audit=false
21 changes: 21 additions & 0 deletions test/fixtures/two-fer/npm/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions test/fixtures/two-fer/npm/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-javascript'],
plugins: [],
};
29 changes: 29 additions & 0 deletions test/fixtures/two-fer/npm/package.json
Original file line number Diff line number Diff line change
@@ -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 ."
}
}
3 changes: 3 additions & 0 deletions test/fixtures/two-fer/npm/two-fer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const twoFer = (name = 'you') => {
return `One for ${name}, one for me.`;
};
15 changes: 15 additions & 0 deletions test/fixtures/two-fer/npm/two-fer.spec.js
Original file line number Diff line number Diff line change
@@ -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.');
});
});
4 changes: 4 additions & 0 deletions test/log.test.mjs
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 4 additions & 0 deletions test/skip.test.mjs
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
9 changes: 9 additions & 0 deletions test/smoke.test.mjs
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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']

Expand Down
4 changes: 4 additions & 0 deletions test/taskid.test.mjs
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 2ac25c7

Please sign in to comment.