|
1 | | -import { endent, first, last, pick, property } from '@dword-design/functions' |
| 1 | +import { |
| 2 | + endent, |
| 3 | + first, |
| 4 | + last, |
| 5 | + pick, |
| 6 | + property, |
| 7 | +} from '@dword-design/functions' |
2 | 8 | import tester from '@dword-design/tester' |
3 | 9 | import testerPluginTmpDir from '@dword-design/tester-plugin-tmp-dir' |
4 | 10 | import axios from 'axios' |
5 | 11 | import packageName from 'depcheck-package-name' |
6 | | -import { execaCommand } from 'execa' |
| 12 | +import { execa, execaCommand } from 'execa' |
7 | 13 | import fs from 'fs-extra' |
8 | 14 | import nuxtDevReady from 'nuxt-dev-ready' |
| 15 | +import ora from 'ora' |
9 | 16 | import outputFiles from 'output-files' |
10 | 17 | import P from 'path' |
11 | 18 | import simpleGit from 'simple-git' |
@@ -99,6 +106,58 @@ export default tester( |
99 | 106 | await kill(nuxt.pid) |
100 | 107 | } |
101 | 108 | }, |
| 109 | + nuxt2: async () => { |
| 110 | + await execaCommand('git init') |
| 111 | + await execaCommand('git config user.email "[email protected]"') |
| 112 | + await execaCommand('git config user.name "foo"') |
| 113 | + await outputFiles({ |
| 114 | + 'content/home.md': '', |
| 115 | + 'nuxt.config.js': endent` |
| 116 | + export default { |
| 117 | + modules: [ |
| 118 | + '~/../src/index.js', |
| 119 | + '${packageName`@nuxt/content`}', |
| 120 | + ], |
| 121 | + } |
| 122 | + `, |
| 123 | + }) |
| 124 | + await execaCommand('git add .') |
| 125 | + await execaCommand('git commit -m init') |
| 126 | + await fs.outputFile('content/home.md', 'foo') |
| 127 | + await execaCommand('git add .') |
| 128 | + await execaCommand('git commit -m update') |
| 129 | + |
| 130 | + const git = simpleGit() |
| 131 | + |
| 132 | + const log = await git.log({ |
| 133 | + file: P.join('content', 'home.md'), |
| 134 | + }) |
| 135 | + |
| 136 | + const createdAt = new Date(log.all |> last |> property('date')) |
| 137 | + |
| 138 | + const updatedAt = new Date(log.latest.date) |
| 139 | + await fs.remove('node_modules') |
| 140 | + await fs.symlink( |
| 141 | + P.join('..', 'node_modules', '.cache', 'nuxt2', 'node_modules'), |
| 142 | + 'node_modules', |
| 143 | + ) |
| 144 | + |
| 145 | + const nuxt = execa(P.join('node_modules', '.bin', 'nuxt'), ['dev']) |
| 146 | + try { |
| 147 | + await nuxtDevReady() |
| 148 | + expect( |
| 149 | + axios.get('http://localhost:3000/_content/home') |
| 150 | + |> await |
| 151 | + |> property('data') |
| 152 | + |> pick(['createdAt', 'updatedAt']), |
| 153 | + ).toEqual({ |
| 154 | + createdAt: createdAt.toISOString(), |
| 155 | + updatedAt: updatedAt.toISOString(), |
| 156 | + }) |
| 157 | + } finally { |
| 158 | + await kill(nuxt.pid) |
| 159 | + } |
| 160 | + }, |
102 | 161 | works: async () => { |
103 | 162 | await execaCommand('git init') |
104 | 163 | await execaCommand('git config user.email "[email protected]"') |
@@ -149,7 +208,17 @@ export default tester( |
149 | 208 | [ |
150 | 209 | testerPluginTmpDir(), |
151 | 210 | { |
152 | | - before: () => execaCommand('base prepublishOnly'), |
| 211 | + before: async () => { |
| 212 | + const spinner = ora('Installing Nuxt 2').start() |
| 213 | + await fs.outputFile( |
| 214 | + P.join('node_modules', '.cache', 'nuxt2', 'package.json'), |
| 215 | + JSON.stringify({}), |
| 216 | + ) |
| 217 | + await execaCommand('yarn add nuxt@^2 @nuxt/content@^1', { |
| 218 | + cwd: P.join('node_modules', '.cache', 'nuxt2'), |
| 219 | + }) |
| 220 | + spinner.stop() |
| 221 | + }, |
153 | 222 | }, |
154 | 223 | { |
155 | 224 | beforeEach: async () => { |
|
0 commit comments