-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add unit tests for the framework #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sniperadmin
wants to merge
5
commits into
Kinrany:main
Choose a base branch
from
sniperadmin:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bdea864
feat: add jest configuration and test cases for the framework
sniperadmin b354262
Merge branch 'feat/unit-test'
sniperadmin 9123beb
feat: add coverage workflow
sniperadmin bbab2fa
feat: add p5 constants to the sketch payload
sniperadmin b17eff7
feat: add ts support and re export p5
sniperadmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
name: Coverage-Monitor | ||
on: [pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Install npm | ||
run: npm install | ||
|
||
- name: Test | ||
run: npx jest --coverage | ||
|
||
- name: Monitor coverage | ||
uses: slavcodev/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
clover_file: "./coverage/clover.xml" | ||
threshold_alert: 70 | ||
threshold_warning: 80 |
This file contains hidden or 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,3 @@ | ||
module.exports = { | ||
presets: ["@babel/preset-env"] | ||
} |
This file contains hidden or 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,27 @@ | ||
module.exports = { | ||
|
||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
'^~/(.*)$': '<rootDir>/src/$1', | ||
'^vue$': 'vue/dist/vue.common.js' | ||
}, | ||
moduleFileExtensions: [ | ||
// 'ts', | ||
'js', | ||
'vue', | ||
'json' | ||
], | ||
testEnvironment: 'jsdom', | ||
setupFiles: ["jest-canvas-mock"], | ||
transform: { | ||
// '^.+\\.ts$': 'ts-jest', | ||
'^.+\\.js$': 'babel-jest', | ||
'.*\\.(vue)$': 'vue-jest', | ||
}, | ||
transformIgnorePatterns: ['/node_modules/(?!p5)'], | ||
collectCoverage: false, | ||
collectCoverageFrom: [ | ||
'<rootDir>/src/**/*.vue', | ||
// '<rootDir>/pages/**/*.vue' | ||
] | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,107 @@ | ||
import { | ||
mount, | ||
createLocalVue | ||
} from '@vue/test-utils' | ||
import p5 from '@/p5.vue' | ||
|
||
let wrapper; | ||
|
||
describe('p5', () => { | ||
beforeEach(() => { | ||
let localVue = createLocalVue() | ||
wrapper = mount(p5, { | ||
localVue, | ||
}) | ||
}) | ||
|
||
it('should mount', () => { | ||
expect(wrapper.vm).toBeTruthy() | ||
}) | ||
|
||
|
||
it('should return exact computed events', () => { | ||
// console.log(wrapper.vm.p5Events) | ||
expect(wrapper.vm.p5Events).toStrictEqual([ | ||
'preload', 'setup', | ||
'draw', 'deviceMoved', | ||
'deviceTurned', 'deviceShaken', | ||
'keyPressed', 'keyReleased', | ||
'keyTyped', 'mouseMoved', | ||
'mouseDragged', 'mousePressed', | ||
'mouseReleased', 'mouseClicked', | ||
'doubleClicked', 'mouseWheel', | ||
'touchStarted', 'touchMoved', | ||
'touchEnded', 'windowResized' | ||
]) | ||
}) | ||
|
||
|
||
it('should return P5 constants', () => { | ||
/** | ||
* HALF_PI PI QUARTER_PI TAU TWO_PI DEGREES RADIANS | ||
*/ | ||
const mockComponent = { | ||
template: ` | ||
<p5 @sketch="sketch"></p5> | ||
`, | ||
data() { | ||
return { | ||
skObj: null | ||
} | ||
}, | ||
methods: { | ||
sketch(sk) { | ||
this.skObj = sk | ||
} | ||
} | ||
} | ||
|
||
const mockWrapper = mount(mockComponent, { | ||
components: {p5} | ||
}) | ||
|
||
const data = mockWrapper.vm.skObj | ||
|
||
expect(data.HALF_PI).toStrictEqual(1.5707963267948966) | ||
expect(data.PI).toStrictEqual(3.141592653589793) | ||
expect(data.QUARTER_PI).toStrictEqual(0.7853981633974483) | ||
expect(data.TAU).toStrictEqual(6.283185307179586) | ||
expect(data.TWO_PI).toStrictEqual(6.283185307179586) | ||
}) | ||
|
||
xit('should return rest of structure events', () => { | ||
/** | ||
* | ||
preload() setup() | ||
draw() remove() | ||
disableFriendlyErrors | ||
noLoop() loop() | ||
isLooping() push() | ||
pop() redraw() p5() | ||
*/ | ||
}); | ||
|
||
|
||
xit('should return all P5 classes', () => { | ||
/** | ||
* p5.Graphics | ||
* p5.MediaElement | ||
* p5.File | ||
* p5.Color | ||
* p5.Geometry | ||
* p5.Element | ||
* p5.TypedDict | ||
* p5.NumberDict | ||
* p5.Image | ||
* p5.Table | ||
* p5.TableRow | ||
* p5.PrintWriter | ||
* p5.XML | ||
* p5.Vector | ||
* p5.Font | ||
* p5.Shader | ||
* p5.Camera | ||
*/ | ||
}); | ||
|
||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one works!
However, I think this approach needs to be checked as I may think it could be done better than this.
{ key, value }
set of the p5 constants firstsketch
contextThe cons of this approach:
Workarounds
In the test file, I tested the component as if I am reusing it (re-usability). It returns the constants needed