Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Feb 1, 2024
1 parent e046768 commit 95ef46f
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 1 deletion.
15 changes: 14 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@
const { configs } = require('@nullvoxpopuli/eslint-configs');

// accommodates: JS, TS, ESM, and CJS
module.exports = configs.node();
const config = configs.node();

module.exports = {
...config,
overrides: [
...config.overrides,
{
files: ['**/*.test.ts'],
rules: {
'n/no-unpublished-import': 'off',
},
},
],
};
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ jobs:
- uses: wyvox/action-setup-pnpm@v3
- name: Lint
run: pnpm lint

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: wyvox/action-setup-pnpm@v3
- run: pnpm test

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
"@nullvoxpopuli/eslint-configs": "^3.2.2",
"@tsconfig/node21": "^21.0.1",
"@tsconfig/strictest": "^2.0.2",
"@types/common-tags": "^1.8.4",
"@types/fs-extra": "^11.0.4",
"@types/jscodeshift": "^0.11.11",
"@types/node": "^20.11.15",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"common-tags": "^1.8.2",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"prettier": "^3.2.4",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions src/fixes/ember.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { stripIndent } from 'common-tags';
import { describe, expect as hardAssert, test } from 'vitest';

import { fixEmberReferences } from './ember.js';

const expect = hardAssert.soft;

describe('fixReferences', () => {
test('match ember-source', () => {
let code = stripIndent`
/// <reference types="ember-source/whatever/module">"
export const two = 2;`;

let result = fixEmberReferences(code);

expect(result).toBe(`export const two = 2;`);
});

test('match multiple ember-source', () => {
let code = stripIndent`
/// <reference types="ember-source/whatever/module">"
/// <reference types="ember-source/whatever1/module">"
/// <reference types="ember-source/whatever2/module">"
export const two = 2;`;

let result = fixEmberReferences(code);

expect(result).toBe(`export const two = 2;`);
});

test('ignore non-specified', () => {
let code = stripIndent`
/// <reference types="not-ember-source/whatever/module">"
export const two = 2;`;

let result = fixEmberReferences(code);

expect(result).toBe(code);
});
});
45 changes: 45 additions & 0 deletions src/fixes/glint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { stripIndent } from 'common-tags';
import { describe, expect as hardAssert, test } from 'vitest';

import { fixGTSExtensions, fixOwnReferences } from './glint.js';

const expect = hardAssert.soft;

describe('fixGTSExtensions', () => {
test('works', () => {
let code = stripIndent`
import x from './foo.gts';
`;

let result = fixGTSExtensions(code);

expect(result).toBe(`import x from "./foo";`);
});
});

describe('fixOwnReferences', () => {
test('removes multiple', () => {
let code = stripIndent`
/// <reference types="node_modules/@glint/whatever/module">"
/// <reference types="node_modules/@glint/whatever2/module">"
/// <reference types="node_modules/@glint/whatever5/module">"
export const two = 2;`;

let result = fixOwnReferences(code);

expect(result).toBe(`export const two = 2;`);
});

test(' does not remove more than what is specified', () => {
let code = stripIndent`
/// <reference types="@glint/whatever/module">"
/// <reference types="node_modules/@glint/whatever2/module">"
export const two = 2;`;

let result = fixOwnReferences(code);

expect(result).toBe(stripIndent`
/// <reference types="@glint/whatever/module">"
export const two = 2;`);
});
});
75 changes: 75 additions & 0 deletions src/fixes/typescript.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { stripIndent } from 'common-tags';
import { describe, expect as hardAssert, test } from 'vitest';

import { fixReferences } from './typescript.js';

const expect = hardAssert.soft;

describe('fixReferences', () => {
test('defaults: match ember-source', () => {
let code = stripIndent`
/// <reference types="ember-source/whatever/module">"
export const two = 2;`;

let result = fixReferences(code);

expect(result).toBe(`export const two = 2;`);
});

test('defaults: match multiple ember-source', () => {
let code = stripIndent`
/// <reference types="ember-source/whatever/module">"
/// <reference types="ember-source/whatever1/module">"
/// <reference types="ember-source/whatever2/module">"
export const two = 2;`;

let result = fixReferences(code);

expect(result).toBe(`export const two = 2;`);
});

test('defaults: ignore non-specified', () => {
let code = stripIndent`
/// <reference types="not-ember-source/whatever/module">"
export const two = 2;`;

let result = fixReferences(code);

expect(result).toBe(code);
});

test('custom: works', () => {
let code = stripIndent`
/// <reference types="@glint/whatever/module">"
export const two = 2;`;

let result = fixReferences(code, { types: '@glint' });

expect(result).toBe(`export const two = 2;`);
});

test('custom: removes multiple', () => {
let code = stripIndent`
/// <reference types="@glint/whatever/module">"
/// <reference types="@glint/whatever2/module">"
/// <reference types="@glint/whatever5/module">"
export const two = 2;`;

let result = fixReferences(code, { types: '@glint' });

expect(result).toBe(`export const two = 2;`);
});

test('custom: does not remove more than what is specified', () => {
let code = stripIndent`
/// <reference types="@glint/whatever/module">"
/// <reference types="node_modules/@glint/whatever2/module">"
export const two = 2;`;

let result = fixReferences(code, { types: '@glint' });

expect(result).toBe(stripIndent`
/// <reference types="node_modules/@glint/whatever2/module">"
export const two = 2;`);
});
});

0 comments on commit 95ef46f

Please sign in to comment.