Skip to content
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

fix: Prettify everything #1683

Merged
merged 4 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions game_frontend/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"module-resolver",
{
"cwd": "babelrc",
"root": [
"./src"
],
"root": ["./src"],
"alias": {
"features": "./src/redux/features",
"theme": "./src/theme",
Expand All @@ -29,11 +27,7 @@
}
}
],
[
"@babel/plugin-proposal-class-properties",
{},
"class-properties"
],
["@babel/plugin-proposal-class-properties", {}, "class-properties"],
"transform-optional-chaining"
]
}
}
8 changes: 4 additions & 4 deletions game_frontend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"singleQuote": true,
"semi": false,
"printWidth": 100
}
"singleQuote": true,
"semi": false,
"printWidth": 100
}
2 changes: 1 addition & 1 deletion game_frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"standard.enable": true,
"eslint.enable": true
}
}
2 changes: 1 addition & 1 deletion game_frontend/cypress/fixtures/gameState.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
],
"turnCount": 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Avatar worker', () => {
it('returns wait action if code does not return an action', () => {
const avatarCode = {
code: `def next_turn(world_state, avatar_state):
return False`
return False`,
}

const expectedAction = { action_type: 'wait' }
Expand All @@ -29,7 +29,7 @@ describe('Avatar worker', () => {
it('returns wait action and prints syntax warning on syntax error', () => {
const avatarCode = {
code: `def next_turn(world_state, avatar_state):
return MoveAction(direction.)`
return MoveAction(direction.)`,
}

const expectedAction = { action_type: 'wait' }
Expand All @@ -42,7 +42,7 @@ describe('Avatar worker', () => {
.its('store')
.invoke('getState')
.its('consoleLog.logs')
.then(logs => {
.then((logs) => {
const log = logs.entries().next().value[1]
expect(log).to.deep.equal('SyntaxError: invalid syntax\n')
})
Expand All @@ -51,7 +51,7 @@ describe('Avatar worker', () => {
it('returns wait action and prints indentation warning on indentation error', () => {
const avatarCode = {
code: `def next_turn(world_state, avatar_state):
return MoveAction(direction.NORTH)`
return MoveAction(direction.NORTH)`,
}

const expectedAction = { action_type: 'wait' }
Expand All @@ -64,27 +64,29 @@ return MoveAction(direction.NORTH)`
.its('store')
.invoke('getState')
.its('consoleLog.logs')
.then(logs => {
.then((logs) => {
const log = logs.entries().next().value[1]
expect(log).to.deep.equal('IndentationError: expected an indented block after function definition on line 1\n')
expect(log).to.deep.equal(
'IndentationError: expected an indented block after function definition on line 1\n'
)
})
})

it('prints with one print', () => {
const avatarCode = {
code: `def next_turn(world_state, avatar_state):
print('I AM A PRINT STATEMENT')
return MoveAction(direction.NORTH)`
return MoveAction(direction.NORTH)`,
}

const expectedAction = {
action_type: 'move',
options: {
direction: {
x: 0,
y: 1
}
}
y: 1,
},
},
}

const expectedLog = 'I AM A PRINT STATEMENT\n'
Expand All @@ -97,17 +99,17 @@ return MoveAction(direction.NORTH)`
code: `def next_turn(world_state, avatar_state):
print('I AM A PRINT STATEMENT')
print('I AM ALSO A PRINT STATEMENT')
return MoveAction(direction.NORTH)`
return MoveAction(direction.NORTH)`,
}

const expectedAction = {
action_type: 'move',
options: {
direction: {
x: 0,
y: 1
}
}
y: 1,
},
},
}

const expectedLog = `I AM A PRINT STATEMENT
Expand All @@ -124,17 +126,17 @@ I AM ALSO A PRINT STATEMENT\n`
return MoveAction(direction.NORTH)

def foo():
print('I AM A NESTED PRINT')`
print('I AM A NESTED PRINT')`,
}

const expectedAction = {
action_type: 'move',
options: {
direction: {
x: 0,
y: 1
}
}
y: 1,
},
},
}

const expectedLog = `I AM A NESTED PRINT
Expand All @@ -147,7 +149,7 @@ I AM NOT A NESTED PRINT\n`
const avatarCode = {
code: `def next_turn(world_state, avatar_state):
print('THIS CODE IS BROKEN')
return None`
return None`,
}

const expectedAction = { action_type: 'wait' }
Expand All @@ -164,31 +166,29 @@ def next_turn(world_map, avatar_state):
global turn_count
turn_count += 1
print(turn_count)
return MoveAction(direction.NORTH)`
return MoveAction(direction.NORTH)`,
}

const expectedAction = {
action_type: 'move',
options: {
direction: {
x: 0,
y: 1
}
}
y: 1,
},
},
}

const firstExpectedLog = '1\n'

testAvatarCode(avatarCode, expectedAction, firstExpectedLog)

cy.fixture('gameState.json').then(gameState => {
cy.fixture('gameState.json').then((gameState) => {
gameState.turnCount = 2
cy.window()
.its('store')
.invoke('dispatch', {
type: 'features/Game/SOCKET_GAME_STATE_RECEIVED',
payload: gameState
})
cy.window().its('store').invoke('dispatch', {
type: 'features/Game/SOCKET_GAME_STATE_RECEIVED',
payload: gameState,
})
})

const secondExpectedLog = '2\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('Avatar worker in a web worker', () => {
while True:
pass
return MoveAction(direction.NORTH)
`
`,
}

const expectedAction = {
action_type: 'wait'
action_type: 'wait',
}

const expectedLog =
Expand Down
7 changes: 3 additions & 4 deletions game_frontend/cypress/support/avatarCodeTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export function testAvatarCode(avatarCode, expectedAction, expectedLog) {
cy.loadGameWithAvatarCode(avatarCode)

cy.fixture('gameState.json').then(gameState => {
cy.fixture('gameState.json').then((gameState) => {
cy.window()
.its('store')
.invoke('dispatch', { type: 'features/Game/SOCKET_GAME_STATE_RECEIVED', payload: gameState })
Expand All @@ -13,15 +13,14 @@ export function testAvatarCode(avatarCode, expectedAction, expectedLog) {
}

export function checkComputedTurnResult(expectedAction, expectedLog) {

const getComputedTurnResult = win => {
const getComputedTurnResult = (win) => {
const state = win.store.getState()
return state.action.avatarAction
}

cy.window()
.pipe(getComputedTurnResult)
.should(computedTurnResult => {
.should((computedTurnResult) => {
assert.isObject(computedTurnResult)

const avatarAction = computedTurnResult.action
Expand Down
62 changes: 29 additions & 33 deletions game_frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const student_access_code = 'AB123'

Cypress.Commands.add('login', () => {
cy.request('/login/teacher/')
cy.getCookie('csrftoken').then(csrfToken => {
cy.getCookie('csrftoken').then((csrfToken) => {
cy.request({
method: 'POST',
url: '/login/teacher/',
Expand All @@ -32,16 +32,16 @@ Cypress.Commands.add('login', () => {
'auth-username': username,
'auth-password': password,
csrfmiddlewaretoken: csrfToken.value,
'teacher_login_view-current_step': 'auth'
}
'teacher_login_view-current_step': 'auth',
},
})
cy.visit('/')
})
})

Cypress.Commands.add('studentLogin', () => {
cy.request('/login/student/')
cy.getCookie('csrftoken').then(csrfToken => {
cy.getCookie('csrftoken').then((csrfToken) => {
cy.request({
method: 'POST',
url: '/login/student/',
Expand All @@ -50,24 +50,24 @@ Cypress.Commands.add('studentLogin', () => {
body: {
access_code: student_access_code,
csrfmiddlewaretoken: csrfToken.value,
}
},
})
cy.getCookie('csrftoken').then(csrfToken => {
cy.request({
method: 'POST',
url: `/login/student/${student_access_code}/`,
failOnStatusCode: true,
form: true,
body: {
username: student_username,
password: password,
csrfmiddlewaretoken: csrfToken.value,
}
cy.getCookie('csrftoken').then((csrfToken) => {
cy.request({
method: 'POST',
url: `/login/student/${student_access_code}/`,
failOnStatusCode: true,
form: true,
body: {
username: student_username,
password: password,
csrfmiddlewaretoken: csrfToken.value,
},
})
cy.visit('/')
})
cy.visit('/')
})
})
})

Cypress.Commands.add('logout', () => {
cy.request('/logout/')
Expand All @@ -76,7 +76,7 @@ Cypress.Commands.add('logout', () => {

Cypress.Commands.add('addTestGame', () => {
cy.request('/teach/kurono/dashboard/')
cy.getCookie('csrftoken').then(csrfToken => {
cy.getCookie('csrftoken').then((csrfToken) => {
cy.request({
method: 'POST',
url: '/teach/kurono/dashboard/',
Expand All @@ -86,44 +86,40 @@ Cypress.Commands.add('addTestGame', () => {
name: game_name,
game_class: class_id,
worksheet: worksheet_id,
csrfmiddlewaretoken: csrfToken.value
}
csrfmiddlewaretoken: csrfToken.value,
},
})
})
})

Cypress.Commands.add('visitAGame', () => {
cy.request('/kurono/api/games/').then(response => {
cy.request('/kurono/api/games/').then((response) => {
const games = response.body
// just get the first game it can find
let testGameId = Object.keys(games)[0]
cy.fixture('initialState.json').then(initialState => {
cy.fixture('initialState.json').then((initialState) => {
cy.visit(`/kurono/play/${testGameId}/`, {
onBeforeLoad: win => {
onBeforeLoad: (win) => {
win.initialState = initialState
}
},
})
})
})
})

Cypress.Commands.add('loadGameWithAvatarCode', avatarCode => {
Cypress.Commands.add('loadGameWithAvatarCode', (avatarCode) => {
cy.intercept('GET', '/kurono/api/code/*', avatarCode)

cy.visitAGame()

cy.window()
.its('store')
.invoke('dispatch', { type: 'features/AvatarWorker/INITIALIZE_PYODIDE' })
cy.window().its('store').invoke('dispatch', { type: 'features/AvatarWorker/INITIALIZE_PYODIDE' })

const isAvatarWorkerInitialized = win => {
const isAvatarWorkerInitialized = (win) => {
const state = win.store.getState()
return state.avatarWorker.initialized
}

cy.window()
.pipe(isAvatarWorkerInitialized, { timeout: 20000 })
.should('eq', true)
cy.window().pipe(isAvatarWorkerInitialized, { timeout: 20000 }).should('eq', true)
})
//
//
Expand Down
3 changes: 2 additions & 1 deletion game_frontend/djangoBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const handlebarsTemplatePath = Path.resolve(
const bundler = new Bundler(file, options)

function getReactURL(entryPointHTML) {
const regex = /(<script src="\/static\/react\/)(.*\.js)("><\/script>\n?<script src="\/static\/react\/webWorker)/g
const regex =
/(<script src="\/static\/react\/)(.*\.js)("><\/script>\n?<script src="\/static\/react\/webWorker)/g
return regex.exec(entryPointHTML)[2]
}

Expand Down
Loading