1
0
mirror of https://github.com/sasjs/lint.git synced 2026-01-07 20:50:04 +00:00

chore: spec fixes

This commit is contained in:
2022-08-15 21:57:18 +05:00
parent 4772aa70c6
commit 5290339c9e
2 changed files with 56 additions and 20 deletions

View File

@@ -1,9 +1,8 @@
import path from 'path'
import * as fileModule from '@sasjs/utils/file' import * as fileModule from '@sasjs/utils/file'
import * as getProjectRootModule from './getProjectRoot'
import * as getLintConfigModule from './getLintConfig' import * as getLintConfigModule from './getLintConfig'
import { DefaultLintConfiguration } from './getLintConfig' import { getProjectRoot, DefaultLintConfiguration, isIgnored } from '.'
import { LintConfig } from '../types' import { LintConfig } from '../types'
import { isIgnored } from './isIgnored'
describe('isIgnored', () => { describe('isIgnored', () => {
it('should return true if provided path matches the patterns from .gitignore', async () => { it('should return true if provided path matches the patterns from .gitignore', async () => {
@@ -20,11 +19,32 @@ describe('isIgnored', () => {
.spyOn(fileModule, 'readFile') .spyOn(fileModule, 'readFile')
.mockImplementationOnce(async () => 'sasjs') .mockImplementationOnce(async () => 'sasjs')
jest const projectRoot = await getProjectRoot()
.spyOn(getProjectRootModule, 'getProjectRoot') const pathToTest = path.join(projectRoot, 'sasjs')
.mockImplementationOnce(async () => '')
const ignored = await isIgnored('sasjs') const ignored = await isIgnored(pathToTest)
expect(ignored).toBeTruthy()
})
it('should return true if top level path of provided path is in .gitignore', async () => {
jest
.spyOn(getLintConfigModule, 'getLintConfig')
.mockImplementationOnce(
async () => new LintConfig(DefaultLintConfiguration)
)
jest
.spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => true)
jest
.spyOn(fileModule, 'readFile')
.mockImplementationOnce(async () => 'sasjs/common')
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, 'sasjs/common/init/init.sas')
const ignored = await isIgnored(pathToTest)
expect(ignored).toBeTruthy() expect(ignored).toBeTruthy()
}) })
@@ -34,12 +54,30 @@ describe('isIgnored', () => {
.spyOn(fileModule, 'fileExists') .spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => false) .mockImplementationOnce(async () => false)
jest const projectRoot = await getProjectRoot()
.spyOn(getProjectRootModule, 'getProjectRoot') const pathToTest = path.join(projectRoot, 'sasjs')
.mockImplementationOnce(async () => '')
const ignored = await isIgnored( const ignored = await isIgnored(
'sasjs', pathToTest,
new LintConfig({
...DefaultLintConfiguration,
ignoreList: ['sasjs']
})
)
expect(ignored).toBeTruthy()
})
it('should return true if top level path of provided path is in ignoreList (.sasjslint)', async () => {
jest
.spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => false)
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, 'sasjs/common/init/init.sas')
const ignored = await isIgnored(
pathToTest,
new LintConfig({ new LintConfig({
...DefaultLintConfiguration, ...DefaultLintConfiguration,
ignoreList: ['sasjs'] ignoreList: ['sasjs']
@@ -56,12 +94,11 @@ describe('isIgnored', () => {
jest.spyOn(fileModule, 'readFile').mockImplementationOnce(async () => '') jest.spyOn(fileModule, 'readFile').mockImplementationOnce(async () => '')
jest const projectRoot = await getProjectRoot()
.spyOn(getProjectRootModule, 'getProjectRoot') const pathToTest = path.join(projectRoot, 'sasjs')
.mockImplementationOnce(async () => '')
const ignored = await isIgnored( const ignored = await isIgnored(
'sasjs', pathToTest,
new LintConfig(DefaultLintConfiguration) new LintConfig(DefaultLintConfiguration)
) )
@@ -69,12 +106,11 @@ describe('isIgnored', () => {
}) })
it('should return false if provided path is equal to projectRoot', async () => { it('should return false if provided path is equal to projectRoot', async () => {
jest const projectRoot = await getProjectRoot()
.spyOn(getProjectRootModule, 'getProjectRoot') const pathToTest = path.join(projectRoot, '')
.mockImplementationOnce(async () => '')
const ignored = await isIgnored( const ignored = await isIgnored(
'', pathToTest,
new LintConfig(DefaultLintConfiguration) new LintConfig(DefaultLintConfiguration)
) )

View File

@@ -7,7 +7,7 @@ import { LintConfig } from '../types'
/** /**
* A function to check if file/folder path matches any pattern from .gitignore or ignoreList (.sasjsLint) * A function to check if file/folder path matches any pattern from .gitignore or ignoreList (.sasjsLint)
* *
* @param fPath absolute path of file or folder * @param {string} fPath - absolute path of file or folder
* @returns {Promise<boolean>} true if path matches the patterns from .gitignore file otherwise false * @returns {Promise<boolean>} true if path matches the patterns from .gitignore file otherwise false
*/ */
export const isIgnored = async ( export const isIgnored = async (