Skip to content

Commit

Permalink
adds happy path test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattxwang committed Feb 12, 2023
1 parent 3a73bd6 commit 31d76ad
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function showNextSteps() {
stripIndent(`
${picocolors.green(`You can now lint your CSS files using:
npx stylelint "**/*.css"`)}
${picocolors.dim(`We recommend customizing Stylelint:
https://stylelint.io/user-guide/customize/`)}
`),
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/valid-env/clean-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"license": "MIT",
"author": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
7 changes: 7 additions & 0 deletions test/fixtures/valid-env/reset-state.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/sh

rm -f .stylelintrc.json
rm -f package.json
rm -f package-lock.json
rm -rf node_modules
cp clean-package.json package.json
26 changes: 25 additions & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// eslint-disable-next-line node/no-unpublished-import
import { describe, expect, it } from 'vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { execFileSync } from 'node:child_process';

const inputs = {
noPackageJson: 'test/fixtures/no-package-json',
stylelintConfigExists: 'test/fixtures/stylelint-config-exists',
validEnv: 'test/fixtures/valid-env',
};

function getProjectRoot(context) {
Expand All @@ -17,7 +18,30 @@ function setup(pathToTest, projectRoot, args = []) {
});
}

function cleanupGenFiles() {
const pathsToCleanup = [inputs.validEnv];

for (let pathToTest of pathsToCleanup) {
execFileSync('./reset-state.sh', [], {
// eslint-disable-next-line no-undef
cwd: `${__dirname}/../${pathToTest}`,
});
}
}

vi.mock('execa');

describe('stylelint-create', () => {
afterEach(() => {
cleanupGenFiles();
});

it('should succeed in a valid env', (context) => {
const projectRoot = getProjectRoot(context);

expect(setup(inputs.validEnv, projectRoot)).toMatch(/You can now lint your CSS files using/);
});

it('should not proceed if a Stylelint config already exists in the directory', (context) => {
const projectRoot = getProjectRoot(context);

Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: ['**/*.test.{js,mjs,cjs}'],
watchExclude: ['**/node_modules/**', 'test/fixtures/**'],
},
});

0 comments on commit 31d76ad

Please sign in to comment.