Skip to content

Commit

Permalink
chore: start new aio tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Oct 16, 2024
1 parent 7026709 commit d1e77c1
Show file tree
Hide file tree
Showing 13 changed files with 705 additions and 1,020 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@nuxtjs/sitemap": "^6.1.2",
"nuxt-link-checker": "^3.1.2",
"nuxt-og-image": "^3.0.4",
"nuxt-schema-org": "^3.4.0",
"nuxt-schema-org": "^3.4.1",
"nuxt-seo-utils": "^5.0.0",
"nuxt-site-config": "^2.2.18",
"nuxt-site-config-kit": "^2.2.18"
Expand Down
1,314 changes: 464 additions & 850 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const SitemapModule: NuxtSEOModule = {
icon: 'i-carbon-load-balancer-application',
description: 'Powerfully flexible XML Sitemaps that integrate seamlessly.',
repo: 'nuxt-modules/sitemap',
npm: '@nuxtjs/seo',
npm: '@nuxtjs/sitemap',
}

export const OgImageModule: NuxtSEOModule = {
Expand Down
3 changes: 2 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default defineNuxtModule<ModuleOptions>({
if (!config.enabled) {
return
}
for (const module of modules)
for (const module of modules) {
await installModule(await resolvePath(module.npm), {}, nuxt)
}
},
})
83 changes: 0 additions & 83 deletions test/fixtures/basic/__runtime__/breadcrumbs.nuxt.test.ts

This file was deleted.

8 changes: 6 additions & 2 deletions test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ export default defineNuxtConfig({
NuxtSeo,
'@nuxt/test-utils/module',
],

nitro: {
prerender: {
failOnError: false,
},
},

site: {
url: 'https://local.nuxtseo.com',
},
sitemap: {
credits: false, // breaks snapshot
},
compatibilityDate: '2024-08-07',
})
35 changes: 0 additions & 35 deletions test/generate.old.ts

This file was deleted.

102 changes: 102 additions & 0 deletions test/integration/base.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { createResolver } from '@nuxt/kit'
import { $fetch, setup } from '@nuxt/test-utils/e2e'
import { describe, expect, it } from 'vitest'
import { extractSeoHead } from '../utils'

const { resolve } = createResolver(import.meta.url)

process.env.NODE_ENV = 'production'

await setup({
rootDir: resolve('../fixtures/basic'),
server: true,
nuxtConfig: {
app: {
baseURL: '/base',
},
},
})

describe('base url', () => {
it('seo utils - default', async () => {
// extract the <head>
const html = await $fetch('/base')
expect(extractSeoHead(html)).toMatchInlineSnapshot(`
"<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:type" content="website">
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1">
<title>@nuxtjs&#x2F;seo</title>
<link rel="canonical" href="https://local.nuxtseo.com/base">
<meta property="og:title" content="@nuxtjs/seo">
<meta property="og:url" content="https://local.nuxtseo.com/base">
<meta property="og:site_name" content="@nuxtjs/seo">
<meta name="description" content="The all-in-one SEO layer for Nuxt 3.">
<meta property="og:description" content="The all-in-one SEO layer for Nuxt 3.">"
`)
})
it('sitemap - default', async () => {
// extract the <head>
const xml = await $fetch('/base/sitemap.xml')
expect(xml).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/base/__sitemap__/style.xsl"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://local.nuxtseo.com/base</loc>
</url>
<url>
<loc>https://local.nuxtseo.com/base/about</loc>
</url>
</urlset>"
`)
})
it('robots - default', async () => {
// extract the <head>
const txt = await $fetch('/base/robots.txt')
expect(txt).toMatchInlineSnapshot(`
"# START nuxt-robots (indexable)
User-agent: *
Disallow:
Sitemap: https://local.nuxtseo.com/sitemap.xml
# END nuxt-robots"
`)
})
it('schema.org - default', async () => {
// extract the <head>
const txt = await $fetch('/base')
// extract schema.org from <script type="application/ld+json" id="schema-org-graph"></script>
const schemaOrg = JSON.parse(txt.match(/<script type="application\/ld\+json" id="schema-org-graph">([\s\S]*)<\/script>/)?.[1])
expect(schemaOrg).toMatchInlineSnapshot(`
{
"@context": "https://schema.org",
"@graph": [
{
"@id": "https://local.nuxtseo.com/#website",
"@type": "WebSite",
"description": "The all-in-one SEO layer for Nuxt 3.",
"name": "@nuxtjs/seo",
"url": "https://local.nuxtseo.com",
},
{
"@id": "https://local.nuxtseo.com/base/#webpage",
"@type": "WebPage",
"description": "The all-in-one SEO layer for Nuxt 3.",
"isPartOf": {
"@id": "https://local.nuxtseo.com/#website",
},
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"https://local.nuxtseo.com/base",
],
},
],
"url": "https://local.nuxtseo.com/base",
},
],
}
`)
})
})
105 changes: 105 additions & 0 deletions test/integration/prod.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { createResolver } from '@nuxt/kit'
import { $fetch, setup } from '@nuxt/test-utils/e2e'
import { describe, expect, it } from 'vitest'
import { extractSeoHead } from '../utils'

const { resolve } = createResolver(import.meta.url)

process.env.NODE_ENV = 'production'

await setup({
rootDir: resolve('../fixtures/basic'),
server: true,
nuxtConfig: {
site: {
url: 'https://local.nuxtseo.com',
},
sitemap: {
credits: false, // breaks snapshot
},
},
})

describe('dev', () => {
it('seo utils - default', async () => {
// extract the <head>
const html = await $fetch('/')
expect(extractSeoHead(html)).toMatchInlineSnapshot(`
"<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:type" content="website">
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1">
<title>@nuxtjs&#x2F;seo</title>
<link rel="canonical" href="https://local.nuxtseo.com/">
<meta property="og:title" content="@nuxtjs/seo">
<meta property="og:url" content="https://local.nuxtseo.com/">
<meta property="og:site_name" content="@nuxtjs/seo">
<meta name="description" content="The all-in-one SEO layer for Nuxt 3.">
<meta property="og:description" content="The all-in-one SEO layer for Nuxt 3.">"
`)
})
it('sitemap - default', async () => {
// extract the <head>
const xml = await $fetch('/sitemap.xml')
expect(xml).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://local.nuxtseo.com/</loc>
</url>
<url>
<loc>https://local.nuxtseo.com/about</loc>
</url>
</urlset>"
`)
})
it('robots - default', async () => {
// extract the <head>
const txt = await $fetch('/robots.txt')
expect(txt).toMatchInlineSnapshot(`
"# START nuxt-robots (indexable)
User-agent: *
Disallow:
Sitemap: https://local.nuxtseo.com/sitemap.xml
# END nuxt-robots"
`)
})
it('schema.org - default', async () => {
// extract the <head>
const txt = await $fetch('/')
// extract schema.org from <script type="application/ld+json" id="schema-org-graph"></script>
const schemaOrg = JSON.parse(txt.match(/<script type="application\/ld\+json" id="schema-org-graph">([\s\S]*)<\/script>/)?.[1])
expect(schemaOrg).toMatchInlineSnapshot(`
{
"@context": "https://schema.org",
"@graph": [
{
"@id": "https://local.nuxtseo.com/#website",
"@type": "WebSite",
"description": "The all-in-one SEO layer for Nuxt 3.",
"name": "@nuxtjs/seo",
"url": "https://local.nuxtseo.com",
},
{
"@id": "https://local.nuxtseo.com/#webpage",
"@type": "WebPage",
"description": "The all-in-one SEO layer for Nuxt 3.",
"isPartOf": {
"@id": "https://local.nuxtseo.com/#website",
},
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"https://local.nuxtseo.com",
],
},
],
"url": "https://local.nuxtseo.com",
},
],
}
`)
})
})
3 changes: 0 additions & 3 deletions test/nuxt/tsconfig.json

This file was deleted.

Loading

0 comments on commit d1e77c1

Please sign in to comment.