-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 94e89df
Showing
16 changed files
with
9,749 additions
and
0 deletions.
There are no files selected for viewing
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,2 @@ | ||
node_modules/ | ||
public/*.js |
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,2 @@ | ||
FROM nginx:1.17 | ||
COPY . /usr/share/nginx/html |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 The GitHub Training Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,3 @@ | ||
# Tic Tac Toe Game | ||
|
||
Learn GitHub Actions through a fun little game. |
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`App Contains the compiled JavaScript 1`] = `"!function(e){var t={};function n(r){if(t[r])return t[r].exports;var l=t[r]={i:r,l:!1,exports:{}};return e[r].call(l.exports,l,l.exports,n),l.l=!0,l.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var l in e)n.d(r,l,function(t){return e[t]}.bind(null,l));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=1)}([function(e,t,n){\\"use strict\\";n.r(t),n.d(t,\\"default\\",(function(){return r}));class r{constructor(e,t){this.p1=e,this.p2=t,this.board=[[null,null,null],[null,null,null],[null,null,null]],this.player=Math.random()<.5?this.p1:this.p2,this.sym=\\"X\\"}turn(e,t){t=t||e,this.board[e][t]=this.sym}nextPlayer(){this.player=this.player===this.p1?this.p2:this.p1,this.sym=\\"X\\"===this.sym?\\"O\\":\\"X\\"}hasWinner(){return this.rowWin()||this.colWin()||this.diagWin()}rowWin(){let e=!1;for(let t=0;t<3;t++){const n=this.board[t];null!==n[0]&&(e=e||n[0]===n[1]&&n[0]===n[2])}return e}colWin(){let e=!1;for(let t=0;t<3;t++){const n=this.board;null!==n[0][t]&&(e=e||n[0][t]===n[1][t]&&n[0][t]===n[2][t])}return e}diagWin(){const e=this.board;return null!==e[0][0]&&e[0][0]===e[1][1]&&e[0][0]===e[2][2]||null!==e[0][2]&&e[0][2]===e[1][1]&&e[0][2]===e[2][0]}}},function(e,t,n){n(2),e.exports=n(0)},function(e,t,n){\\"use strict\\";n.r(t);var r=n(0);let l,o;for(;!l;)l=window.prompt(\\"Enter player 1 name:\\");for(;!o&&l!==o;)o=window.prompt(l===o?\`Please enter a different name than \${l}.\`:\\"Enter player 2 name:\\");window.onload=()=>{document.getElementById(\\"p1Name\\").innerText=l,document.getElementById(\\"p2Name\\").innerText=o;let e=0,t=0;!function n(l,o){document.getElementById(\\"win\\").style.display=\\"none\\",document.getElementById(\\"turn\\").style.display=\\"inline\\",document.getElementById(\\"p1Score\\").innerText=e,document.getElementById(\\"p2Score\\").innerText=t;const i=new r.default(l,o),u=document.getElementById(\\"player\\");u.innerText=i.player,document.querySelectorAll(\\"#tictactoe td\\").forEach(r=>{r.innerText=\\"\\",r.onclick=c=>{r.onclick=void 0,c.target.innerText=i.sym,c.target.onclick=void 0;const[d,a]=c.target.classList;i.turn(d,a),i.hasWinner()?(document.getElementById(\\"winner\\").innerText=i.player,document.getElementById(\\"win\\").style.display=\\"inline\\",document.getElementById(\\"turn\\").style.display=\\"none\\",i.player===l?document.getElementById(\\"p1Score\\").innerText=++e:document.getElementById(\\"p2Score\\").innerText=++t,document.getElementById(\\"newGame\\").style.display=\\"inline\\",document.getElementById(\\"newGame\\").onclick=()=>n(l,o),document.querySelectorAll(\\"td\\").forEach(e=>{e.onclick=void 0})):(i.nextPlayer(),u.innerText=i.player)}})}(l,o)}}]);"`; |
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,108 @@ | ||
const Game = require('../src/game').default | ||
const fs = require('fs') | ||
|
||
describe('App', () => { | ||
it('Contains the compiled JavaScript', async (done) => { | ||
fs.readFile('./public/main.js', 'utf8', (err, data) => { | ||
expect(err).toBe(null) | ||
expect(data).toMatchSnapshot() | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Game', () => { | ||
let game, p1, p2 | ||
beforeEach(() => { | ||
p1 = 'Salem' | ||
p2 = 'Nate' | ||
game = new Game(p1, p2) | ||
}) | ||
|
||
describe('Game', () => { | ||
it('Initializes with two players', async () => { | ||
expect(game.p1).toBe('Salem') | ||
expect(game.p2).toBe('Nate') | ||
}) | ||
|
||
it('Initializes with an empty board', async () => { | ||
for (let r = 0; r < game.board.length; r++) { | ||
for (let c = 0; c < game.board[r].lenght; c++) { | ||
expect(game.board[r][c]).toBeUndefined() | ||
} | ||
} | ||
}) | ||
|
||
it('Starts the game with a random player', async () => { | ||
Math.random = () => 0.4 | ||
expect(new Game(p1, p2).player).toBe('Salem') | ||
|
||
Math.random = () => 0.6 | ||
expect(new Game(p1, p2).player).toBe('Nate') | ||
}) | ||
}) | ||
|
||
describe('turn', () => { | ||
it("Inserts an 'X' into the top center", async () => { | ||
game.turn(0, 1) | ||
expect(game.board[0][1]).toBe('X') | ||
}) | ||
|
||
it("Inserts an 'X' into the top left", async () => { | ||
game.turn(0) | ||
expect(game.board[0][0]).toBe('X') | ||
}) | ||
}) | ||
|
||
describe('nextPlayer', () => { | ||
it('Sets the current player to be whoever it is not', async () => { | ||
Math.random = () => 0.4 | ||
const game = new Game(p1, p2) | ||
expect(game.player).toBe('Salem') | ||
game.nextPlayer() | ||
expect(game.player).toBe('Nate') | ||
}) | ||
}) | ||
|
||
describe('hasWinner', () => { | ||
it('Wins if any row is filled', async () => { | ||
for (let r = 0; r < game.board.length; r++) { | ||
for (let c = 0; c < game.board[r].length; c++) { | ||
game.board[r][c] = 'X' | ||
} | ||
expect(game.hasWinner()).toBe(true) | ||
|
||
for (let c = 0; c < game.board[r].length; c++) { | ||
game.board[r][c] = null | ||
} | ||
} | ||
}) | ||
|
||
it('Wins if any column is filled', async () => { | ||
for (let r = 0; r < game.board.length; r++) { | ||
for (let c = 0; c < game.board[r].length; c++) { | ||
game.board[c][r] = 'X' | ||
} | ||
expect(game.hasWinner()).toBe(true) | ||
|
||
for (let c = 0; c < game.board[r].length; c++) { | ||
game.board[c][r] = null | ||
} | ||
} | ||
}) | ||
|
||
it('Wins if down-left diagonal is filled', async () => { | ||
for (let r = 0; r < game.board.length; r++) { | ||
game.board[r][r] = 'X' | ||
} | ||
expect(game.hasWinner()).toBe(true) | ||
}) | ||
|
||
it('Wins if up-right diagonal is filled', async () => { | ||
for (let r = 0; r < game.board.length; r++) { | ||
game.board[2 - r][r] = 'X' | ||
} | ||
expect(game.hasWinner()).toBe(true) | ||
}) | ||
}) | ||
}) |
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,7 @@ | ||
The team would like: | ||
- [ ] branch protections | ||
- [ ] required review approvals | ||
- [ ] easy way to see when enough approvals has been achieved | ||
- [ ] matrix build | ||
- [ ] save build artifacts | ||
- [ ] dedicated test job |
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,12 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 'current' | ||
} | ||
} | ||
] | ||
] | ||
} |
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,41 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const files = { | ||
'/public/index.css': { | ||
content: fs.readFileSync(path.join(__dirname, 'public', 'index.css'), 'utf8'), | ||
type: 'text/css' | ||
}, | ||
'/public/main.js': { | ||
content: fs.readFileSync(path.join(__dirname, 'public', 'main.js'), 'utf8'), | ||
type: 'text/javascript' | ||
}, | ||
'/': { | ||
content: fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8'), | ||
type: 'text/html' | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format | ||
* @param {Object} event - API Gateway Lambda Proxy Input Format | ||
* | ||
* Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html | ||
* @param {Object} context | ||
* | ||
* Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html | ||
* @returns {Object} object - API Gateway Lambda Proxy Output Format | ||
* | ||
*/ | ||
exports.lambdaHandler = async (event, context) => { | ||
// This will either be /, /public/index.css, or /public/main.js | ||
const requestPath = event.path | ||
const { content, type } = files[requestPath] | ||
|
||
return { | ||
headers: { 'content-type': type }, | ||
statusCode: 200, | ||
body: content | ||
} | ||
} |
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,59 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>TicTacToe</title> | ||
|
||
<link href="public/index.css" type="text/css" rel="stylesheet" /> | ||
<script src="public/main.js"></script> | ||
</head> | ||
<body> | ||
<div id="app"> | ||
<div> | ||
<h2 id="turn">It's <span id="player"></span>'s turn!</h2> | ||
<h2 id="win"> | ||
<span id="winner"></span> wins! | ||
<button id="newGame">Play again?</button> | ||
</h2> | ||
</div> | ||
<div id="game"> | ||
<table id="tictactoe"> | ||
<tr"0"> | ||
<td class="0 0"></td> | ||
<td class="0 1"></td> | ||
<td class="0 2"></td> | ||
</tr> | ||
<tr> | ||
<td class="1 0"></td> | ||
<td class="1 1"></td> | ||
<td class="1 2"></td> | ||
</tr> | ||
<tr> | ||
<td class="2 0"></td> | ||
<td class="2 1"></td> | ||
<td class="2 2"></td> | ||
</tr> | ||
</table> | ||
<div id="score"> | ||
<h2>Score</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th id="p1Name"></th> | ||
<th id="p2Name"></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td id="p1Score">0</td> | ||
<td id="p2Score">0</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.