-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
239 additions
and
106 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
fixtures/import-order/package.json → fixtures/lint-format/package.json
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
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`sku format errors are fixed: fixableLintError.ts 1`] = ` | ||
const foo = () => 'foo'; | ||
`; | ||
|
||
exports[`sku format errors are fixed: importOrder1.ts 1`] = ` | ||
import './reset'; // side-effect imports should stay put | ||
import path from 'path'; // built-in | ||
import someModule from 'some-module'; // external | ||
import utils from 'src/utils'; // internal | ||
import distantParent from '../../../parent'; // parents | ||
import Parent from '../parent'; // parents | ||
import LocalComponent from './LocalComponent'; // sibling | ||
import myself from '.'; // index | ||
import styles from './styles.less'; // styles | ||
import vanillaStyles from './vanillaStyles.css'; // styles | ||
`; | ||
|
||
exports[`sku format errors are fixed: importOrder2.ts 1`] = ` | ||
import c from '../c'; | ||
import a from './a'; | ||
import b from './b'; | ||
import aStyle from './a.css'; | ||
import bStyle from './b.css'; | ||
import cStyle from '../c.css'; | ||
`; | ||
|
||
exports[`sku format errors are fixed: unformattedFile2.ts 1`] = ` | ||
import { something } from 'with-double-quotes'; | ||
const indented = 'indented'; | ||
const foo = [ | ||
'something "really" long', | ||
'that has to be moved', | ||
'to multiple lines', | ||
"so we can 'test' trailing commas", | ||
]; | ||
`; | ||
|
||
exports[`sku lint lint errors are reported: typescriptFile.ts 1`] = ` | ||
stdout: Linting | ||
Checking code with TypeScript compiler | ||
src/typescriptFile.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'. | ||
`; | ||
|
||
exports[`sku lint lint errors are reported: unformattedFile1.js 1`] = ` | ||
stdout: Linting | ||
Checking code with TypeScript compiler | ||
Checking code with Prettier | ||
Paths: **/*.{ts,cts,mts,tsx,js,cjs,mjs,jsx,md,less,css} | ||
src/unformattedFile1.js | ||
To fix this issue, run 'npx sku format' | ||
`; | ||
|
||
exports[`sku lint lint errors are reported: utils.test.ts 1`] = ` | ||
stdout: Linting | ||
Checking code with TypeScript compiler | ||
Checking code with Prettier | ||
Paths: **/*.{ts,cts,mts,tsx,js,cjs,mjs,jsx,md,less,css} | ||
Checking code with ESLint | ||
Paths: . | ||
1:1 error Unexpected console statement no-console | ||
3:4 error Unexpected focused test jest/no-focused-tests | ||
4:7 error 'foo' is never reassigned. Use 'const' instead prefer-const | ||
✖ 3 problems (3 errors, 0 warnings) | ||
1 error and 0 warnings potentially fixable with the \`--fix\` option. | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
const path = require('path'); | ||
const fs = require('fs/promises'); | ||
const dedent = require('dedent'); | ||
const { runSkuScriptInDir } = require('@sku-private/test-utils'); | ||
|
||
const appDirectory = path.dirname( | ||
require.resolve('@sku-fixtures/lint-format/sku.config.js'), | ||
); | ||
const srcDirectory = path.join(appDirectory, 'src'); | ||
const testFile = (fileName) => path.join(srcDirectory, fileName); | ||
|
||
const filesToLint = { | ||
'utils.test.ts': dedent/* ts */ ` | ||
console.log('foo'); | ||
it.only('should test something', () => { | ||
let foo = true; | ||
expect(foo).toBe(true); | ||
});\n`, | ||
'typescriptFile.ts': dedent/* ts */ ` | ||
const foo: number = 'a string'; | ||
`, | ||
'unformattedFile1.js': dedent/* js */ ` | ||
import { something } from "with-double-quotes"; | ||
const indented = 'indented'; | ||
const foo = [ | ||
"something \"really\" long", | ||
"that has to be moved", | ||
'to multiple lines', | ||
"so we can 'test' trailing commas" | ||
]; | ||
`, | ||
}; | ||
|
||
const filesToFormat = { | ||
'importOrder1.ts': dedent/* ts */ ` | ||
import './reset'; // side-effect imports should stay put | ||
import LocalComponent from './LocalComponent'; // sibling | ||
import Parent from '../parent'; // parents | ||
import someModule from 'some-module'; // external | ||
import vanillaStyles from './vanillaStyles.css'; // styles | ||
import distantParent from '../../../parent'; // parents | ||
import myself from '.'; // index | ||
import path from 'path'; // built-in | ||
import styles from './styles.less'; // styles | ||
import utils from 'src/utils'; // internal | ||
`, | ||
'importOrder2.ts': dedent/* ts */ ` | ||
import aStyle from './a.css'; | ||
import bStyle from './b.css'; | ||
import cStyle from '../c.css'; | ||
import b from './b'; | ||
import a from './a'; | ||
import c from '../c'; | ||
`, | ||
'fixableLintError.ts': dedent/* ts */ ` | ||
const foo = () => { | ||
return 'foo'; | ||
}; | ||
`, | ||
'unformattedFile2.ts': dedent/* ts */ ` | ||
import { something } from "with-double-quotes"; | ||
const indented = 'indented'; | ||
const foo = [ | ||
"something \"really\" long", | ||
"that has to be moved", | ||
'to multiple lines', | ||
"so we can 'test' trailing commas" | ||
]; | ||
`, | ||
}; | ||
|
||
beforeEach(async () => { | ||
await fs.mkdir(srcDirectory, { recursive: true }); | ||
}); | ||
|
||
afterEach(async () => { | ||
await fs.rm(srcDirectory, { recursive: true, force: true }); | ||
}); | ||
|
||
describe('sku lint', () => { | ||
expect.addSnapshotSerializer({ | ||
serialize: (val) => { | ||
const { stdout } = val; | ||
// Remove some logs that contain file paths that are unique to the machine | ||
const sanitizedStdout = stdout | ||
.split('\n') | ||
.filter((line) => !line.includes('sku/fixtures/lint-format')) | ||
.join('\n'); | ||
|
||
return dedent` | ||
stdout: ${sanitizedStdout} | ||
`; | ||
}, | ||
test: (val) => typeof val === 'object' && val.hasOwnProperty('stdout'), | ||
}); | ||
|
||
test.each(Object.keys(filesToLint))( | ||
'lint errors are reported: %s', | ||
async (fileName) => { | ||
const filePath = testFile(fileName); | ||
await fs.writeFile(filePath, filesToLint[fileName]); | ||
|
||
let result; | ||
|
||
try { | ||
await runSkuScriptInDir('lint', appDirectory); | ||
} catch (err) { | ||
result = { stderr: err.stderr, stdout: err.stdout }; | ||
} | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toMatchSnapshot(); | ||
}, | ||
); | ||
}); | ||
|
||
describe('sku format', () => { | ||
expect.addSnapshotSerializer({ | ||
serialize: (val) => val, | ||
test: (val) => typeof val === 'string', | ||
}); | ||
|
||
test.each(Object.keys(filesToFormat))( | ||
'errors are fixed: %s', | ||
async (fileName) => { | ||
const filePath = testFile(fileName); | ||
await fs.writeFile(filePath, filesToFormat[fileName]); | ||
|
||
await runSkuScriptInDir('format', appDirectory); | ||
|
||
const result = await fs.readFile(filePath, { encoding: 'utf-8' }); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}, | ||
); | ||
}); |
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