Skip to content

Commit

Permalink
Re-bundle the package
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscarrollsmith committed Dec 10, 2023
1 parent f9dbb9b commit 51e7944
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 83 deletions.
36 changes: 19 additions & 17 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { extract } from '@extractus/feed-extractor'

jest.mock('@extractus/feed-extractor', () => ({
extract: jest.fn()
}));
}))

// Mock the core module
jest.mock('@actions/core', () => ({
setFailed: jest.fn()
}));
}))

// Mock the fs module except for readFileSync
jest.mock('fs', () => ({
Expand All @@ -22,7 +22,7 @@ jest.mock('fs', () => ({
existsSync: jest.fn(),
mkdirSync: jest.fn(),
writeFileSync: jest.fn()
}));
}))

beforeEach(() => {
// Reset the mocks and environment variables
Expand All @@ -32,9 +32,9 @@ beforeEach(() => {
process.env.INPUT_PARSER_OPTIONS = JSON.stringify({ useISODateFormat: true })
process.env.INPUT_FETCH_OPTIONS = '{}'
process.env.INPUT_REMOVE_PUBLISHED = 'false'
});
})

describe('fetchRssFeed function', () => {
describe('fetchRssFeed function', () => {
describe('Validation tests', () => {
it('should set failed if feed URL is not provided', async () => {
// Clear the environment variable for feed URL
Expand All @@ -47,7 +47,7 @@ describe('fetchRssFeed function', () => {
expect(core.setFailed).toHaveBeenCalledWith(
'After parsing, feedURL is not an array of non-empty strings'
)
});
})

it('should set failed if feed URL is not a valid URL', async () => {
// Set an invalid URL for feed URL
Expand All @@ -60,7 +60,7 @@ describe('fetchRssFeed function', () => {
expect(core.setFailed).toHaveBeenCalledWith(
'Invalid URL provided: invalid URL'
)
});
})

it('should set failed if file path is not provided', async () => {
// Clear the environment variable for file path
Expand All @@ -70,8 +70,10 @@ describe('fetchRssFeed function', () => {
await fetchRssFeed()

// Expect that core.setFailed was called with the expected error message
expect(core.setFailed).toHaveBeenCalledWith('After parsing, filePath is not an array of non-empty strings')
});
expect(core.setFailed).toHaveBeenCalledWith(
'After parsing, filePath is not an array of non-empty strings'
)
})

it('should set failed if file extension is not .json', async () => {
// Set the environment variable for file path with an invalid extension
Expand All @@ -84,8 +86,8 @@ describe('fetchRssFeed function', () => {
expect(core.setFailed).toHaveBeenCalledWith(
'File path is invalid: File path extension must be .json'
)
});
});
})
})

describe('Input Parsing', () => {
it('should set failed if parserOptions is invalid JSON', async () => {
Expand Down Expand Up @@ -201,7 +203,7 @@ describe('fetchRssFeed function', () => {
'./feed1.json',
'./feed2.json'
])

// Verify that extract function is mocked
expect(jest.isMockFunction(extract)).toBe(true)

Expand All @@ -212,11 +214,11 @@ describe('fetchRssFeed function', () => {
await fetchRssFeed()

// Verify that extract was called twice with the correct arguments
expect(extract).toHaveBeenCalledTimes(2);
expect(extract).toHaveBeenCalledTimes(2)
expect(extract).toHaveBeenCalledWith(
'https://example.com/feed1',
{ useISODateFormat: true },
{}
'https://example.com/feed1',
{ useISODateFormat: true },
{}
)
expect(extract).toHaveBeenCalledWith(
'https://example.com/feed2',
Expand Down Expand Up @@ -352,7 +354,7 @@ describe('fetchRssFeed function', () => {
it('should set failed if directory cannot be created', async () => {
// Return javascript object from extract function
extract.mockResolvedValueOnce({ title: 'Test Feed' })

// Setup
fs.existsSync.mockReturnValue(true)
fs.writeFileSync.mockImplementationOnce(() => {
Expand Down
149 changes: 108 additions & 41 deletions dist/index.js

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

Loading

0 comments on commit 51e7944

Please sign in to comment.