diff --git a/.dockerignore b/.dockerignore index 1837405..49e4608 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,19 @@ -**/node_modules -**/.next -**/dist \ No newline at end of file +Dockerfile +.dockerignore +.git +.gitignore +.gitattributes +README.md +.npmrc +.prettierrc +.eslintrc.cjs +.graphqlrc +.editorconfig +.svelte-kit +.vscode +node_modules +build +package +**/.env +**/dist +*.local \ No newline at end of file diff --git a/.eslintignore b/.eslintignore index 3897265..7241103 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,7 +6,7 @@ node_modules .env .env.* !.env.example - +*.local # Ignore files for PNPM, NPM and YARN pnpm-lock.yaml package-lock.json diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 0000000..0404c10 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,27 @@ +name: Playwright Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm install -g pnpm && pnpm install + - name: Install Playwright Browsers + run: pnpm exec playwright install --with-deps + - name: Run Playwright tests + run: pnpm exec playwright test + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.prettierignore b/.prettierignore index 3897265..8d47d4e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,7 @@ node_modules .env .env.* !.env.example +*.local # Ignore files for PNPM, NPM and YARN pnpm-lock.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..22783c6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM node:18-alpine AS builder + +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ + +RUN npm install -g pnpm && \ + echo "Installing pnpm..." +RUN pnpm install --frozen-lockfile && \ + echo "Installing deps..." + +COPY . . + +RUN pnpm run build && \ + echo "Building..." && \ + pnpm prune --production + + +FROM node:18-alpine + +WORKDIR /app + +COPY --from=builder /app/build build/ +COPY --from=builder /app/node_modules node_modules/ +COPY package.json . + +EXPOSE 3000 + +ENV NODE_ENV=production +CMD [ "node", "build" ] \ No newline at end of file diff --git a/README.md b/README.md index 73ce66f..89309e9 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,30 @@ -# create-svelte +# Hello world, this is my personal site -Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). +Featuring a blog, projects, current social accounts, skills and so on and so on, look at [Technical Features](#technical-features) -## Creating a project +## Stack info -If you're seeing this, you've probably already done this step. Congrats! +I focused on researching the best possible modern solutions to frontend and worked on my previous knowledge of svelte. -```bash -# create a new project in the current directory -npm create svelte@latest +Javascript, Typescript +Framework: Sveltekit +CSS: Tailwindcss, postcss +[MDsveX](https://mdsvex.pngwn.io/) for markdown text file processing with plugins +Dockerfile, node-adapter for custom deploy +AWS S3 for static assets +AWS lambda for automation -# create a new project in my-app -npm create svelte@latest my-app -``` +## Technical Features -## Developing +- A possibility of great .md file processing with ability to use svelte components in .md +- Rss feed +- Sitemap, robots, Manifest, Workers +- Some playwright testing -Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: +[CSP from rodnylab](https://rodneylab.com/sveltekit-content-security-policy/) -```bash -npm run dev +## Credits -# or start the server and open the app in a new browser tab -npm run dev -- --open -``` - -## Building - -To create a production version of your app: - -```bash -npm run build -``` - -You can preview the production build with `npm run preview`. - -> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. - - - -TODO: REcompose based on KkosmetickySalon project +This project is using [Skeleton Labs UI / Component / utils Library](https://www.skeleton.dev/) for sveltekit. +This project used some logic of gitpod.io sveltekit blog with MIT License, however they have shortly pulled their site off of github, their source or license now unreachable. +I have learned some svelte tricks used here from [Matt Croat](https://matia.xyz) alias [https://joyofcode.xyz/] diff --git a/mdsvex.config.js b/mdsvex.config.js index 04f00d0..028ba3c 100644 --- a/mdsvex.config.js +++ b/mdsvex.config.js @@ -2,11 +2,7 @@ import { defineMDSveXConfig as defineConfig } from 'mdsvex'; import remarkExternalLinks from 'remark-external-links'; import remarkSetImagePath from './src/lib/utils/remark-set-image-path.js'; import remarkLinkWithImageAsOnlyChild from './src/lib/utils/remark-link-with-image-as-only-child.js'; -import { toString } from 'mdast-util-to-string'; -import rehypeWrap from 'rehype-wrap-all'; import rehypeImgSize from 'rehype-img-size'; -import { h } from 'hastscript'; -import { visit } from 'unist-util-visit'; import remarkUnwrapImages from 'remark-unwrap-images'; import remarkToc from 'remark-toc'; @@ -28,10 +24,8 @@ const config = defineConfig({ // }, /* Plugins */ rehypePlugins: [ - [rehypeSlug] - - // [rehypeWrap, { selector: 'table', wrapper: 'div.overflow-auto' }], - // [rehypeImgSize, { dir: './static' }], + [rehypeSlug], + [rehypeImgSize] // [ // /** Custom rehype plugin to add loading="lazy" to all images */ // () => { @@ -53,7 +47,9 @@ const config = defineConfig({ target: '_blank' }) ], - [remarkUnwrapImages] + [remarkUnwrapImages], + remarkSetImagePath, + remarkLinkWithImageAsOnlyChild // [ // headings, // { @@ -68,8 +64,7 @@ const config = defineConfig({ // } // } // ], - // remarkSetImagePath, - // remarkLinkWithImageAsOnlyChild, + // remarkHeadingsPermaLinks, // getHeadings ] diff --git a/mdsvex.config.ts b/mdsvex.config.ts deleted file mode 100644 index 1c86991..0000000 --- a/mdsvex.config.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { MdsvexOptions, defineMDSveXConfig as defineConfig } from 'mdsvex'; -import headings from 'rehype-autolink-headings'; -import remarkExternalLinks from 'remark-external-links'; -import slug from 'rehype-slug'; -import remarkSetImagePath from './src/lib/utils/remark-set-image-path.js'; -import remarkLinkWithImageAsOnlyChild from './src/lib/utils/remark-link-with-image-as-only-child.js'; -import { toString } from 'mdast-util-to-string'; -import rehypeWrap from 'rehype-wrap-all'; -import rehypeImgSize from 'rehype-img-size'; -import { h } from 'hastscript'; -import { visit } from 'unist-util-visit'; -import remarkToc from 'remark-toc'; -// import { highlightCode } from './src/lib/utils/highlighter.js'; - -const config: MdsvexOptions = defineConfig({ - extensions: ['.svelte.md', '.md', '.svx'], - smartypants: { - dashes: 'oldschool' - } - // Wait for skeleton to implement Prismjs, for now use in .md files - // highlight: {}, - // layout: { - // blog: './src/lib/components/blog/_blog-layout.svelte', - // project: './src/lib/components/projects/_project-layout.svelte', - // _: './src/lib/components/fallback/_layout.svelte' - // }, - // rehypePlugins: [ - // [rehypeWrap, { selector: 'table', wrapper: 'div.overflow-auto' }], - // [rehypeImgSize, { dir: './static' }], - // [slug], - // [ - // headings, - // { - // behavior: 'prepend', - // headingProperties: {}, - // content: '' - // } - // ] - // ], - // remarkPlugins: [ - // [remarkToc, { maxDepth: 3, tight: true }], - // [remarkExternalLinks, { target: '_blank', rel: 'noreferrer' }], - // remarkSetImagePath, - // remarkLinkWithImageAsOnlyChild, - // remarkHeadingsPermaLinks, - // getHeadings - // ] -}); - -export default config; diff --git a/playwright-ct.config.ts b/playwright-ct.config.ts deleted file mode 100644 index f00cb84..0000000 --- a/playwright-ct.config.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { defineConfig, devices } from '@playwright/experimental-ct-svelte'; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: './', - /* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */ - snapshotDir: './__snapshots__', - /* Maximum time one test can run for. */ - timeout: 10 * 1000, - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - - /* Port to use for Playwright component endpoint. */ - ctPort: 3100, - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, - }, - { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, - }, - { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, - ], -}); diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..d58e542 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,77 @@ +import { defineConfig, devices } from '@playwright/test'; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://127.0.0.1:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry' + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] } + }, + + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] } + }, + + { + name: 'webkit', + use: { ...devices['Desktop Safari'] } + }, + + /* Test against mobile viewports. */ + { + name: 'Mobile Chrome', + use: { ...devices['Pixel 5'] } + }, + { + name: 'Mobile Safari', + use: { ...devices['iPhone 12'] } + } + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ] + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // url: 'http://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); diff --git a/playwright/index.html b/playwright/index.html deleted file mode 100644 index 000deea..0000000 --- a/playwright/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Testing Page - - -
- - - diff --git a/src/content/blog/first-post.md b/src/content/blog/first-post.md index 37266bf..c8d07a2 100644 --- a/src/content/blog/first-post.md +++ b/src/content/blog/first-post.md @@ -8,7 +8,6 @@ tags: published: true image: Feature.jpg --- - ## Svelte Media inside the **Svelte** folder is served from the `static` folder. diff --git a/src/content/blog/postwa.md b/src/content/blog/postwa.md new file mode 100644 index 0000000..f9e4fa3 --- /dev/null +++ b/src/content/blog/postwa.md @@ -0,0 +1,12 @@ +--- +title: w post +excerpt: w post +date: 2021-01-01 +tags: + - first + - post +published: true +image: Feature.jpg +--- + +## Svelte \ No newline at end of file diff --git a/src/content/blog/second-post.md b/src/content/blog/second-post.md index e871a84..930f194 100644 --- a/src/content/blog/second-post.md +++ b/src/content/blog/second-post.md @@ -10,6 +10,18 @@ image: Feature.jpg --- -## Svelte + +## Switching to Self-Hosted Git + +You can check it out on git.mattmor.in, it's a simple encrypted gitea instance running on AWS + +### Media Media inside the **Svelte** folder is server from the `static` folder. + +### Bye Bye Github with your fancy features + +I am ditching the societal value of having a contributions table on my profile, you should view it on git.mattmor.in + + +--- If my contributions in 3d do not work, Github made breaking changes to their frontend and I can't scrape it anymore. \ No newline at end of file diff --git a/src/content/projects/erant.md b/src/content/projects/erant.md new file mode 100644 index 0000000..7a5e887 --- /dev/null +++ b/src/content/projects/erant.md @@ -0,0 +1,15 @@ +--- +title: Erant +excerpt: A SaaS helping SMEs in the tourism sector with virtualization, customer experience & analytics. It got into the republic finale of Soutěž & Podnikej. +date: 2021-01-01 +published: true +image: Feature.jpg +--- + +## Svelte + +Media inside the **Svelte** folder is served from the `static` folder. + +```python + +``` diff --git a/src/content/projects/first-proj.md b/src/content/projects/first-proj.md deleted file mode 100644 index e8ec5df..0000000 --- a/src/content/projects/first-proj.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: First Project -excerpt: This is the first project -date: 2021-01-01 -tags: - - first - - post -published: true -image: Feature.jpg ---- - -## Svelte - -Media inside the **Svelte** folder is served from the `static` folder. - -```python - -input_text = ''' "yahooapis.com", - "hotmail.com", - "gfx.ms", - "afx.ms", - "live.com", -''' -# and so on... - -lines = input_text.split('\n') - -formatted_lines = ['* ' + line.strip()[1:-2] + ' * block' for line in lines if line] - -output_text = '\n'.join(formatted_lines) -print(output_text) - -``` diff --git a/src/content/projects/seedling.md b/src/content/projects/seedling.md new file mode 100644 index 0000000..a18b88c --- /dev/null +++ b/src/content/projects/seedling.md @@ -0,0 +1,27 @@ +--- +title: Seedling +excerpt: An Iot Project, where we built a sensor system for plant care and accompanying app that alerted the user to what their plant needs. We made PCBs, industrial designs, 3D printed cases as clueless students. +date: 2021-01-01 +published: true +image: Feature.jpg +--- + +This is a recollection of my first "startup" journey. + +In 2020, after the onset of Covid, I remembered a presentation I heard from the founder of "Soutěž & Podnikej" Martin Vítek, on a meeting of the Prague Highschool Assembly. +It was an invitation to join their great program guiding highschoolers to launch an idea to financial fruition. The program, now sadly no longer operating, was inspirational to me as entrepreneurship and tech startups for me was a way to bring about a revolution, to solve a problem. +The journey that I embarked on, however, was not something I thought I signed up for. +I have not yet till that point in my life understood the deep rabbit hole of truly understanding a problem, the markets and people's needs, technical difficulties and the state of current technological developments, having the methodologies, networks of contacts and partners and capital at my disposal. + +However what the program gave me was at least a brief outline of where to begin and how to progress. I began with a problem. As I was engaged in discussions and student organizations centered on ecology, especially thanks to being a part of many MUN and EYP conferences, I remembered a paper of the UN FAO called [2050: A third more mouths to feed](https://www.fao.org/newsroom/detail/2050-A-third-more-mouths-to-feed/), basically amongst the array of possibilities - water scarcity, food demand, population will increase + + +[Ben Einsteins LinkedIn post](https://www.linkedin.com/pulse/heres-why-juiceros-press-so-expensive-ben-einstein/) sums up the problem of Hardware startups + +## Svelte + +Media inside the **Svelte** folder is served from the `static` folder. + +```python + +``` diff --git a/src/lib/assets/prism-atom-dark.css b/src/lib/assets/prism-atom-dark.css new file mode 100644 index 0000000..749b17c --- /dev/null +++ b/src/lib/assets/prism-atom-dark.css @@ -0,0 +1,143 @@ +/** + * atom-dark theme for `prism.js` + * Based on Atom's `atom-dark` theme: https://github.com/atom/atom-dark-syntax + * @author Joe Gibson (@gibsjose) + */ + +code[class*="language-"], +pre[class*="language-"] { + color: #c5c8c6; + text-shadow: 0 1px rgba(0, 0, 0, 0.3); + font-family: Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace; + direction: ltr; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + line-height: 1.5; + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; +} + +/* Code blocks */ +pre[class*="language-"] { + padding: 1em; + margin: .5em 0; + overflow: auto; + border-radius: 0.3em; +} + +:not(pre) > code[class*="language-"], +pre[class*="language-"] { + background: #1d1f21; +} + +/* Inline code */ +:not(pre) > code[class*="language-"] { + padding: .1em; + border-radius: .3em; +} + +.token.comment, +.token.prolog, +.token.doctype, +.token.cdata { + color: #7C7C7C; +} + +.token.punctuation { + color: #c5c8c6; +} + +.namespace { + opacity: .7; +} + +.token.property, +.token.keyword, +.token.tag { + color: #96CBFE; +} + +.token.class-name { + color: #FFFFB6; + text-decoration: underline; +} + +.token.boolean, +.token.constant { + color: #99CC99; +} + +.token.symbol, +.token.deleted { + color: #f92672; +} + +.token.number { + color: #FF73FD; +} + +.token.selector, +.token.attr-name, +.token.string, +.token.char, +.token.builtin, +.token.inserted { + color: #A8FF60; +} + +.token.variable { + color: #C6C5FE; +} + +.token.operator { + color: #EDEDED; +} + +.token.entity { + color: #FFFFB6; + cursor: help; +} + +.token.url { + color: #96CBFE; +} + +.language-css .token.string, +.style .token.string { + color: #87C38A; +} + +.token.atrule, +.token.attr-value { + color: #F9EE98; +} + +.token.function { + color: #DAD085; +} + +.token.regex { + color: #E9C062; +} + +.token.important { + color: #fd971f; +} + +.token.important, +.token.bold { + font-weight: bold; +} + +.token.italic { + font-style: italic; +} diff --git a/src/lib/config.ts b/src/lib/config.ts index e073f29..26086be 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -11,7 +11,7 @@ export const github = 'https://github.com/matthieu42morin'; // prettier-ignore export const socialLinks = [ - { title: 'LinkedIn', href: 'https://www.linkedin.com/in/matthieu-morin-7524731a9/', icon: 'fa-brands fa-linkedin'}, + { title: 'LinkedIn', href: 'https://linkedin.com/in/mattmor-in', icon: 'fa-brands fa-linkedin'}, { title: 'Matrix', href: '', icon: './MatrixLogo' }, { title: 'Gitea', href: 'https://git.mattmor.in', icon: './GiteaLogo' }, { title: 'Mastodon', href: 'https://mastodon.social/@matt_mor', icon: 'fa-brands fa-mastodon'}, diff --git a/static/animations/travolta_confused.webp b/static/animations/travolta_confused.webp new file mode 100644 index 0000000..25813ba Binary files /dev/null and b/static/animations/travolta_confused.webp differ diff --git a/static/images/blog/first-posthey/Feature.jpg b/static/images/blog/first-posthey/Feature.jpg new file mode 100644 index 0000000..4c59b98 Binary files /dev/null and b/static/images/blog/first-posthey/Feature.jpg differ diff --git a/static/images/blog/first-posthey/Feature.png b/static/images/blog/first-posthey/Feature.png new file mode 100644 index 0000000..e69de29 diff --git a/static/images/blog/postwa/Feature.jpg b/static/images/blog/postwa/Feature.jpg new file mode 100644 index 0000000..4c59b98 Binary files /dev/null and b/static/images/blog/postwa/Feature.jpg differ diff --git a/static/images/profile-pic.png b/static/images/profile-pic.png index da7a4c9..a34997c 100644 Binary files a/static/images/profile-pic.png and b/static/images/profile-pic.png differ diff --git a/static/images/projects/erant/Feature.jpg b/static/images/projects/erant/Feature.jpg new file mode 100644 index 0000000..4c59b98 Binary files /dev/null and b/static/images/projects/erant/Feature.jpg differ diff --git a/static/images/projects/seedling/Feature.jpg b/static/images/projects/seedling/Feature.jpg new file mode 100644 index 0000000..4c59b98 Binary files /dev/null and b/static/images/projects/seedling/Feature.jpg differ diff --git a/tests-examples/demo-todo-app.spec.ts b/tests-examples/demo-todo-app.spec.ts new file mode 100644 index 0000000..2fd6016 --- /dev/null +++ b/tests-examples/demo-todo-app.spec.ts @@ -0,0 +1,437 @@ +import { test, expect, type Page } from '@playwright/test'; + +test.beforeEach(async ({ page }) => { + await page.goto('https://demo.playwright.dev/todomvc'); +}); + +const TODO_ITEMS = [ + 'buy some cheese', + 'feed the cat', + 'book a doctors appointment' +]; + +test.describe('New Todo', () => { + test('should allow me to add todo items', async ({ page }) => { + // create a new todo locator + const newTodo = page.getByPlaceholder('What needs to be done?'); + + // Create 1st todo. + await newTodo.fill(TODO_ITEMS[0]); + await newTodo.press('Enter'); + + // Make sure the list only has one todo item. + await expect(page.getByTestId('todo-title')).toHaveText([ + TODO_ITEMS[0] + ]); + + // Create 2nd todo. + await newTodo.fill(TODO_ITEMS[1]); + await newTodo.press('Enter'); + + // Make sure the list now has two todo items. + await expect(page.getByTestId('todo-title')).toHaveText([ + TODO_ITEMS[0], + TODO_ITEMS[1] + ]); + + await checkNumberOfTodosInLocalStorage(page, 2); + }); + + test('should clear text input field when an item is added', async ({ page }) => { + // create a new todo locator + const newTodo = page.getByPlaceholder('What needs to be done?'); + + // Create one todo item. + await newTodo.fill(TODO_ITEMS[0]); + await newTodo.press('Enter'); + + // Check that input is empty. + await expect(newTodo).toBeEmpty(); + await checkNumberOfTodosInLocalStorage(page, 1); + }); + + test('should append new items to the bottom of the list', async ({ page }) => { + // Create 3 items. + await createDefaultTodos(page); + + // create a todo count locator + const todoCount = page.getByTestId('todo-count') + + // Check test using different methods. + await expect(page.getByText('3 items left')).toBeVisible(); + await expect(todoCount).toHaveText('3 items left'); + await expect(todoCount).toContainText('3'); + await expect(todoCount).toHaveText(/3/); + + // Check all items in one call. + await expect(page.getByTestId('todo-title')).toHaveText(TODO_ITEMS); + await checkNumberOfTodosInLocalStorage(page, 3); + }); +}); + +test.describe('Mark all as completed', () => { + test.beforeEach(async ({ page }) => { + await createDefaultTodos(page); + await checkNumberOfTodosInLocalStorage(page, 3); + }); + + test.afterEach(async ({ page }) => { + await checkNumberOfTodosInLocalStorage(page, 3); + }); + + test('should allow me to mark all items as completed', async ({ page }) => { + // Complete all todos. + await page.getByLabel('Mark all as complete').check(); + + // Ensure all todos have 'completed' class. + await expect(page.getByTestId('todo-item')).toHaveClass(['completed', 'completed', 'completed']); + await checkNumberOfCompletedTodosInLocalStorage(page, 3); + }); + + test('should allow me to clear the complete state of all items', async ({ page }) => { + const toggleAll = page.getByLabel('Mark all as complete'); + // Check and then immediately uncheck. + await toggleAll.check(); + await toggleAll.uncheck(); + + // Should be no completed classes. + await expect(page.getByTestId('todo-item')).toHaveClass(['', '', '']); + }); + + test('complete all checkbox should update state when items are completed / cleared', async ({ page }) => { + const toggleAll = page.getByLabel('Mark all as complete'); + await toggleAll.check(); + await expect(toggleAll).toBeChecked(); + await checkNumberOfCompletedTodosInLocalStorage(page, 3); + + // Uncheck first todo. + const firstTodo = page.getByTestId('todo-item').nth(0); + await firstTodo.getByRole('checkbox').uncheck(); + + // Reuse toggleAll locator and make sure its not checked. + await expect(toggleAll).not.toBeChecked(); + + await firstTodo.getByRole('checkbox').check(); + await checkNumberOfCompletedTodosInLocalStorage(page, 3); + + // Assert the toggle all is checked again. + await expect(toggleAll).toBeChecked(); + }); +}); + +test.describe('Item', () => { + + test('should allow me to mark items as complete', async ({ page }) => { + // create a new todo locator + const newTodo = page.getByPlaceholder('What needs to be done?'); + + // Create two items. + for (const item of TODO_ITEMS.slice(0, 2)) { + await newTodo.fill(item); + await newTodo.press('Enter'); + } + + // Check first item. + const firstTodo = page.getByTestId('todo-item').nth(0); + await firstTodo.getByRole('checkbox').check(); + await expect(firstTodo).toHaveClass('completed'); + + // Check second item. + const secondTodo = page.getByTestId('todo-item').nth(1); + await expect(secondTodo).not.toHaveClass('completed'); + await secondTodo.getByRole('checkbox').check(); + + // Assert completed class. + await expect(firstTodo).toHaveClass('completed'); + await expect(secondTodo).toHaveClass('completed'); + }); + + test('should allow me to un-mark items as complete', async ({ page }) => { + // create a new todo locator + const newTodo = page.getByPlaceholder('What needs to be done?'); + + // Create two items. + for (const item of TODO_ITEMS.slice(0, 2)) { + await newTodo.fill(item); + await newTodo.press('Enter'); + } + + const firstTodo = page.getByTestId('todo-item').nth(0); + const secondTodo = page.getByTestId('todo-item').nth(1); + const firstTodoCheckbox = firstTodo.getByRole('checkbox'); + + await firstTodoCheckbox.check(); + await expect(firstTodo).toHaveClass('completed'); + await expect(secondTodo).not.toHaveClass('completed'); + await checkNumberOfCompletedTodosInLocalStorage(page, 1); + + await firstTodoCheckbox.uncheck(); + await expect(firstTodo).not.toHaveClass('completed'); + await expect(secondTodo).not.toHaveClass('completed'); + await checkNumberOfCompletedTodosInLocalStorage(page, 0); + }); + + test('should allow me to edit an item', async ({ page }) => { + await createDefaultTodos(page); + + const todoItems = page.getByTestId('todo-item'); + const secondTodo = todoItems.nth(1); + await secondTodo.dblclick(); + await expect(secondTodo.getByRole('textbox', { name: 'Edit' })).toHaveValue(TODO_ITEMS[1]); + await secondTodo.getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); + await secondTodo.getByRole('textbox', { name: 'Edit' }).press('Enter'); + + // Explicitly assert the new text value. + await expect(todoItems).toHaveText([ + TODO_ITEMS[0], + 'buy some sausages', + TODO_ITEMS[2] + ]); + await checkTodosInLocalStorage(page, 'buy some sausages'); + }); +}); + +test.describe('Editing', () => { + test.beforeEach(async ({ page }) => { + await createDefaultTodos(page); + await checkNumberOfTodosInLocalStorage(page, 3); + }); + + test('should hide other controls when editing', async ({ page }) => { + const todoItem = page.getByTestId('todo-item').nth(1); + await todoItem.dblclick(); + await expect(todoItem.getByRole('checkbox')).not.toBeVisible(); + await expect(todoItem.locator('label', { + hasText: TODO_ITEMS[1], + })).not.toBeVisible(); + await checkNumberOfTodosInLocalStorage(page, 3); + }); + + test('should save edits on blur', async ({ page }) => { + const todoItems = page.getByTestId('todo-item'); + await todoItems.nth(1).dblclick(); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).dispatchEvent('blur'); + + await expect(todoItems).toHaveText([ + TODO_ITEMS[0], + 'buy some sausages', + TODO_ITEMS[2], + ]); + await checkTodosInLocalStorage(page, 'buy some sausages'); + }); + + test('should trim entered text', async ({ page }) => { + const todoItems = page.getByTestId('todo-item'); + await todoItems.nth(1).dblclick(); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(' buy some sausages '); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); + + await expect(todoItems).toHaveText([ + TODO_ITEMS[0], + 'buy some sausages', + TODO_ITEMS[2], + ]); + await checkTodosInLocalStorage(page, 'buy some sausages'); + }); + + test('should remove the item if an empty text string was entered', async ({ page }) => { + const todoItems = page.getByTestId('todo-item'); + await todoItems.nth(1).dblclick(); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(''); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); + + await expect(todoItems).toHaveText([ + TODO_ITEMS[0], + TODO_ITEMS[2], + ]); + }); + + test('should cancel edits on escape', async ({ page }) => { + const todoItems = page.getByTestId('todo-item'); + await todoItems.nth(1).dblclick(); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); + await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Escape'); + await expect(todoItems).toHaveText(TODO_ITEMS); + }); +}); + +test.describe('Counter', () => { + test('should display the current number of todo items', async ({ page }) => { + // create a new todo locator + const newTodo = page.getByPlaceholder('What needs to be done?'); + + // create a todo count locator + const todoCount = page.getByTestId('todo-count') + + await newTodo.fill(TODO_ITEMS[0]); + await newTodo.press('Enter'); + + await expect(todoCount).toContainText('1'); + + await newTodo.fill(TODO_ITEMS[1]); + await newTodo.press('Enter'); + await expect(todoCount).toContainText('2'); + + await checkNumberOfTodosInLocalStorage(page, 2); + }); +}); + +test.describe('Clear completed button', () => { + test.beforeEach(async ({ page }) => { + await createDefaultTodos(page); + }); + + test('should display the correct text', async ({ page }) => { + await page.locator('.todo-list li .toggle').first().check(); + await expect(page.getByRole('button', { name: 'Clear completed' })).toBeVisible(); + }); + + test('should remove completed items when clicked', async ({ page }) => { + const todoItems = page.getByTestId('todo-item'); + await todoItems.nth(1).getByRole('checkbox').check(); + await page.getByRole('button', { name: 'Clear completed' }).click(); + await expect(todoItems).toHaveCount(2); + await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); + }); + + test('should be hidden when there are no items that are completed', async ({ page }) => { + await page.locator('.todo-list li .toggle').first().check(); + await page.getByRole('button', { name: 'Clear completed' }).click(); + await expect(page.getByRole('button', { name: 'Clear completed' })).toBeHidden(); + }); +}); + +test.describe('Persistence', () => { + test('should persist its data', async ({ page }) => { + // create a new todo locator + const newTodo = page.getByPlaceholder('What needs to be done?'); + + for (const item of TODO_ITEMS.slice(0, 2)) { + await newTodo.fill(item); + await newTodo.press('Enter'); + } + + const todoItems = page.getByTestId('todo-item'); + const firstTodoCheck = todoItems.nth(0).getByRole('checkbox'); + await firstTodoCheck.check(); + await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); + await expect(firstTodoCheck).toBeChecked(); + await expect(todoItems).toHaveClass(['completed', '']); + + // Ensure there is 1 completed item. + await checkNumberOfCompletedTodosInLocalStorage(page, 1); + + // Now reload. + await page.reload(); + await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); + await expect(firstTodoCheck).toBeChecked(); + await expect(todoItems).toHaveClass(['completed', '']); + }); +}); + +test.describe('Routing', () => { + test.beforeEach(async ({ page }) => { + await createDefaultTodos(page); + // make sure the app had a chance to save updated todos in storage + // before navigating to a new view, otherwise the items can get lost :( + // in some frameworks like Durandal + await checkTodosInLocalStorage(page, TODO_ITEMS[0]); + }); + + test('should allow me to display active items', async ({ page }) => { + const todoItem = page.getByTestId('todo-item'); + await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); + + await checkNumberOfCompletedTodosInLocalStorage(page, 1); + await page.getByRole('link', { name: 'Active' }).click(); + await expect(todoItem).toHaveCount(2); + await expect(todoItem).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); + }); + + test('should respect the back button', async ({ page }) => { + const todoItem = page.getByTestId('todo-item'); + await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); + + await checkNumberOfCompletedTodosInLocalStorage(page, 1); + + await test.step('Showing all items', async () => { + await page.getByRole('link', { name: 'All' }).click(); + await expect(todoItem).toHaveCount(3); + }); + + await test.step('Showing active items', async () => { + await page.getByRole('link', { name: 'Active' }).click(); + }); + + await test.step('Showing completed items', async () => { + await page.getByRole('link', { name: 'Completed' }).click(); + }); + + await expect(todoItem).toHaveCount(1); + await page.goBack(); + await expect(todoItem).toHaveCount(2); + await page.goBack(); + await expect(todoItem).toHaveCount(3); + }); + + test('should allow me to display completed items', async ({ page }) => { + await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); + await checkNumberOfCompletedTodosInLocalStorage(page, 1); + await page.getByRole('link', { name: 'Completed' }).click(); + await expect(page.getByTestId('todo-item')).toHaveCount(1); + }); + + test('should allow me to display all items', async ({ page }) => { + await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); + await checkNumberOfCompletedTodosInLocalStorage(page, 1); + await page.getByRole('link', { name: 'Active' }).click(); + await page.getByRole('link', { name: 'Completed' }).click(); + await page.getByRole('link', { name: 'All' }).click(); + await expect(page.getByTestId('todo-item')).toHaveCount(3); + }); + + test('should highlight the currently applied filter', async ({ page }) => { + await expect(page.getByRole('link', { name: 'All' })).toHaveClass('selected'); + + //create locators for active and completed links + const activeLink = page.getByRole('link', { name: 'Active' }); + const completedLink = page.getByRole('link', { name: 'Completed' }); + await activeLink.click(); + + // Page change - active items. + await expect(activeLink).toHaveClass('selected'); + await completedLink.click(); + + // Page change - completed items. + await expect(completedLink).toHaveClass('selected'); + }); +}); + +async function createDefaultTodos(page: Page) { + // create a new todo locator + const newTodo = page.getByPlaceholder('What needs to be done?'); + + for (const item of TODO_ITEMS) { + await newTodo.fill(item); + await newTodo.press('Enter'); + } +} + +async function checkNumberOfTodosInLocalStorage(page: Page, expected: number) { + return await page.waitForFunction(e => { + return JSON.parse(localStorage['react-todos']).length === e; + }, expected); +} + +async function checkNumberOfCompletedTodosInLocalStorage(page: Page, expected: number) { + return await page.waitForFunction(e => { + return JSON.parse(localStorage['react-todos']).filter((todo: any) => todo.completed).length === e; + }, expected); +} + +async function checkTodosInLocalStorage(page: Page, title: string) { + return await page.waitForFunction(t => { + return JSON.parse(localStorage['react-todos']).map((todo: any) => todo.title).includes(t); + }, title); +} diff --git a/tests/example.spec.ts b/tests/example.spec.ts new file mode 100644 index 0000000..821a748 --- /dev/null +++ b/tests/example.spec.ts @@ -0,0 +1,51 @@ +import { test, expect } from '@playwright/test'; + +test('has title', async ({ page }) => { + await page.goto('/'); + + // Expect a title "to contain" a substring. + await expect(page).toHaveTitle(/Playwright/); +}); + +test('get started link', async ({ page }) => { + await page.goto('/'); + + // Click the Look at my code link. + await page.getByRole('link', { name: 'Look at my code' }).click(); + // Click the get cv link. + await page.getByRole('link', { name: 'Get my CV' }).click(); + + // Expects page to have a heading with the name of Installation. + await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); +}); + +// Blog tests +test('Blog tests', async ({ page }) => { + await page.goto('/blog'); + await page.click('a[href="/about"]'); + expect(page.url()).toBe('http://localhost:513/about'); +}); + +beforeAll(async () => { + browser = await chromium.launch(); +}); + +afterAll(async () => { + await browser.close(); +}); + +beforeEach(async () => { + page = await browser.newPage(); + await page.goto('http://localhost:5000/skills'); // replace with the URL of your skills page +}); + +afterEach(async () => { + await page.close(); +}); + +it('should display the correct skill levels', async () => { + const skills = await page.$$eval('.chip', (elements) => elements.map((el) => el.textContent)); + for (const skill of skills) { + expect(skill).toMatch(/^(Proficient|Experienced|Limited Experience):/); + } +}); diff --git a/vite.config.ts b/vite.config.ts index 1303c4b..36be9c6 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,3 +1,4 @@ +import { sentrySvelteKit } from '@sentry/sveltekit'; import { purgeCss } from 'vite-plugin-tailwind-purgecss'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vitest/config'; @@ -11,9 +12,17 @@ export default defineConfig({ }, build: { // to resolve https://github.com/vitejs/vite/issues/6985 - target: 'esnext', + target: 'esnext' }, + envPrefix: 'PUBLIC_', plugins: [ + sentrySvelteKit({ + sourceMapsUploadOptions: { + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT + }, + telemetry: false + }), sveltekit(), purgeCss({ safelist: { @@ -23,19 +32,22 @@ export default defineConfig({ }), { ...threeMinifier(), enforce: 'pre' } ], - test: { - include: ['src/**/*.{test,spec}.{js,ts}'] + define: { + 'process.env.VITE_BUILD_TIME': JSON.stringify(new Date().toISOString()) }, ssr: { noExternal: ['three'] }, + + test: { + include: ['src/**/*.{test,spec}.{js,ts}'] + }, resolve: { alias: { $lib: path.resolve(__dirname, 'src', 'lib'), $root: path.resolve(__dirname), $src: path.resolve(__dirname, 'src'), - $routes: path.resolve(__dirname, 'src', 'routes'), - $content: path.resolve(__dirname, 'src', 'content') + $routes: path.resolve(__dirname, 'src', 'routes') } } });